BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tarunchitkara
Fluorite | Level 6

I want to import excel file in SAS but sheet count and name is going to change. I need a macro which can take sheet name automatically from excel file and create a dataset.Excel file can have one or more sheets  .If file have multiple sheets it should append all data of all sheets and create one dataset.

 

Any answer will be much appreciated.

 

Thanks

Tarun Chitkara

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Are your files well structured? If not, one issue your going to run into very quickly is mismatched types. A field in one sheet will get imported as a character and numeric in another, preventing you from simply appending all the files together. 

 

What do you feel a macro or proc import does that my solution doesn't? All of the methods will have the issue mentioned above. 

 

 

View solution in original post

7 REPLIES 7
Reeza
Super User

Can you access an Excel file via a libname? If so you can use proc datasets to copy all the sheets over.

Maybe this can help get you started.

 

libname xlib excel 'path to excel file.xlsx';

proc datasets library=work;
copy in=xlib out=work;
run;quit;
tarunchitkara
Fluorite | Level 6
Thank you Rezza for your reply .I will try this option but If use know any macro or using proc import procedure then please let me know.In my framework I am reading one by one file so proc import will be more useful .
SASKiwi
Opal | Level 21

If you want to use PROC IMPORT you would still need to use a LIBNAME with the EXCEL option to get the sheet names that IMPORT requires. Using @Reeza's solution is a lot easier.

Reeza
Super User

Are your files well structured? If not, one issue your going to run into very quickly is mismatched types. A field in one sheet will get imported as a character and numeric in another, preventing you from simply appending all the files together. 

 

What do you feel a macro or proc import does that my solution doesn't? All of the methods will have the issue mentioned above. 

 

 

tarunchitkara
Fluorite | Level 6
Thank you Reeza your solution works.
Ksharp
Super User

Once you successfully assign a libname to that excel file . You can check Sheet name via dictionary.

 

libname xx xlsx '/folders/myfolders/test1.xlsx' ;

proc sql;
select * from dictionary.members where libname='XX';
quit;
tarunchitkara
Fluorite | Level 6
Thak you Ksharp

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 7 replies
  • 5996 views
  • 2 likes
  • 4 in conversation