DATA Step, Macro, Functions and more

PROC IMPORT....multiple sheets

Reply
Occasional Contributor
Posts: 5

PROC IMPORT....multiple sheets

how to import multiple sheets from a single excel workbook without using macro or proc sql.

Trusted Advisor
Posts: 1,131

Re: PROC IMPORT....multiple sheets

Not sure if its possible without the use of macros , as the multiple sheets are to be converted to each separate dataset. It would be interesting to know if there is way to achieve it.
Thanks,
Jag
Trusted Advisor
Posts: 1,627

Re: PROC IMPORT....multiple sheets

Without macros? Simple. Write code to import each sheet, one-by-one.

Frequent Contributor
Posts: 127

Re: PROC IMPORT....multiple sheets

If you have SAS/Access to PC files you can try LIBNAME EXCEL Engine.

 

If your trying to append all the data in different sheets you assign the excel file as a library and read the individual sheets.

 

NOTE: If you see the datasets in the Excel library with "$" trailing then the dataset has to be referenced as FILE.'sheet1$'n

 

Libname file EXCEL "<FilePath>";

PROC SQL ;
select COMPRESS(cat(libname,".","'",memname,"'","n"))
into :ranges separated by ' '
from dictionary.members
where libname = 'FILE'
;
QUIT;

%PUT &ranges;

DATA test;
set &ranges;
run;

LIBNAME File clear;

 

Hope this helps,

Thanks,

Suryakiran

Thanks,
Suryakiran
Trusted Advisor
Posts: 1,627

Re: PROC IMPORT....multiple sheets

Well, @SuryaKiran, that's brilliant, I like it ... but the original request was very stubborn and clear ... no macros, no PROC SQL (and sounds very much like a homework assignment)

SAS Employee
Posts: 285

Re: PROC IMPORT....multiple sheets

The SAS/ACCESS Interface to PC Files engine that you use may depend on your version of SAS and the type of Excel file that you need to import.

 

Here is sample code to import an XLSX file using SAS 9.4 M4:

 

libname xl xlsx 'C:\temp\MyFile.xlsx' access=read;

options validvarname=any validmemname=extend;

proc datasets nolist;
  copy in=xl out=work;
run; quit;

 

Vince DelGobbo

SAS R&D

Ask a Question
Discussion stats
  • 5 replies
  • 288 views
  • 4 likes
  • 5 in conversation