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?

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 984 views
  • 0 likes
  • 3 in conversation