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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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