Import Excel Cross Tab table into SAS

Posted on 2011-04-28
Last Modified: 2014-05-05
Is there a way to import an Excel Cross tab table into SAS without having to reformat it to the SAS format first
Excel                        White   Hispanic   Asian
Age Cat  00-01y    524       845        123
               01-04y    1000     2501       456
               05-14y     895      2512       561

Procedure to manually enter into SAS-I want to avoid this        
input Age $ Race $  Pop $;
00-01y  White       524  
00-01y  Hispanic   845
00-01y  Asian       123
Question by:SASEPI
    LVL 7

    Accepted Solution

    If you have SAS/Access for PC File Formats then with the excel libname engine you can read excel files as if they were SAS data sets.

    libname xls excel '/path_to_spreadsheet/filename.xls';

    data one; set xls.'sheetname$'n;

    If you have only Base SAS then use proc import.

    Author Comment

    Thanks d507201,

    I was able to import it, however, I actually want to merge this dataset with another dataset by age category and race.  I need to do this so I can use the population variable in a calculation. Therefore, I need to assign a race  to each value, (as below) right? or is there a way to do this from the cross tab table;or is there an easy way to convert the cross tab table to the format below.  Thank you.
    age cat   race        population
    00-01y  White       524  
    00-01y  Hispanic   845
    00-01y  Asian       123
    LVL 7

    Assisted Solution

    I'm thinking there's a way to do it using proc transpose but couldn't quickly get it to work.  Here's a sort of brute force approach.

    ** Create a SAS data set that looks like a 2x2 table. ;
    data test; infile cards;
      input ageCat $ white hispanic asian;
    01 5 4 6
    04 8 3 2
    14 10 32 44

    title 'Test';
    proc print data=test;

    data new; set test;
          length race $10;
      if white > 0 then do;
      race='white'; pop=white; output;
      if hispanic > 0 then do;
      race='hispanic'; pop=hispanic; output;
      if asian > 0 then do;
      race='asian'; pop=asian; output;

      keep ageCat race pop;

    title 'new';
    proc print data=new;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
    Read about achieving the basic levels of HRIS security in the workplace.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now