BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ranikeka
Calcite | Level 5
Hi

I would like to Export multiple SAS datasets to one excel file in multiple sheets. Please help with any macro code ?
Thanks
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
No macro need.
If all your sas dataset are under the same fold :

libname x xlsx 'c:\temp\want.xlsx';
libname data v9 'd:\sas\';
proc copy in=data out=x;
run;

View solution in original post

7 REPLIES 7
Kurt_Bremser
Super User

Define "multiple datasets". Are these datasets in different libraries, or all in one library? Do they share a common naming structure (e.g. all dataset names start with the same string)?

ranikeka
Calcite | Level 5
Hi

Yes they all in same library and with same structure name_a,name_b etc..
Thanks
Kurt_Bremser
Super User

First select the names:

proc sql noprint;
select memname into :dsnames separated by " "
from dictionary.tables
where libname = "LIBRARY" and memname like '%NAME';
quit;

Then copy to Excel:

libname ex xlsx "/path to your Excel file";

proc copy in=library out=ex;
select &dsnames.;
run;

or do it in one step with a wildcard:

libname ex xlsx "/path to your Excel file";

proc copy in=library out=ex;
select name:;
run;

The first selection method allows you to use more complicated selection rules.

 

andreas_lds
Jade | Level 19

I am surprised that non of the solution already posted for this problem fits your needs.

If you have AccessTo PcFiles licensed, maybe libname + proc copy is all you need. You won't need a macro, most likely.

Ksharp
Super User
No macro need.
If all your sas dataset are under the same fold :

libname x xlsx 'c:\temp\want.xlsx';
libname data v9 'd:\sas\';
proc copy in=data out=x;
run;
ranikeka
Calcite | Level 5
Great and many thanks 🙏

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 5060 views
  • 3 likes
  • 4 in conversation