BookmarkSubscribeRSS Feed
SASuserlot
Barite | Level 11

I am trying import the excel file into sas, for some reason, I am running into issues where row I want to display as  variable is not working properly. Any help greatly appreciated. I want titles as variable names and read it as data from the next row.

 

PROC IMPORT 
    OUT= YourNewTable
    DATAFILE= "myfolder/excelfilename.xlsx" 
    DBMS=xlsx 
    REPLACE;
    SHEET="Sheet1";
    GETNAMES=YES;
range="Sheet1$A2:L4" RUN;

I used above code, I am getting dataset , variable name as sponsor information then A,B,C . below is the excel sheet

 

 

Annotation.png

5 REPLIES 5
ballardw
Super User

The first row of the file provides the information that SAS uses to create variable names. Since you have two rows of "header" information the results are as you describe. Delete the entire row that contains the "Sponsor Information".

Then import.

SASuserlot
Barite | Level 11
I tried as u suggested, now I am getting the A. B, C.. in varaible I used the rang="sheet1$A2:L5". If possible can you write a code
ballardw
Super User

@SASuserlot wrote:
I tried as u suggested, now I am getting the A. B, C.. in varaible I used the rang="sheet1$A2:L5". If possible can you write a code

remove the range or change it to read the first row.

I really don't use ranges but suppose sheet1$A1:L4 should work.

 

 

SASuserlot
Barite | Level 11

PROC IMPORT
OUT= SDSP
DATAFILE= "C:\Users\xxx\Desktop\New folder\xx\1.xlsx"
DBMS=xlsx
REPLACE;
SHEET="Sheet1";
GETNAMES=yes;
range="Sheet1$A2:0";
/* SCANTEXT=YES;*/
/* USEDATE=YES;*/
/* SCANTIME=YES;*/
RUN;

SASuserlot_0-1601940074679.png

 

SASKiwi
PROC Star

@SASuserlot  - What happens if you remove the RANGE statement?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1673 views
  • 0 likes
  • 3 in conversation