BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
abraham1
Obsidian | Level 7

Hi,

I need to export all supplmentary SAS file (suppae, suppdm, suppds) from Supp Library into multiple sheet of a single excel workbook. I use below method and it is working fine for one dataset. Can you please help me how to proceed.

libname aa 'C:/supp';
proc export 
  data=aa.suppae
  dbms=xlsx 
  outfile="C:/output/test.xlsx" 
  replace;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Use a LIBNAME, and PROC COPY:

libname aa 'C:/supp';
libname xlout xlsx "C:/output/test.xlsx";

proc copy in=aa out=xlout;
select
  suppae
  suppdm
  suppds
;
run;

libname xlout clear;

If you want all datasets in the library to be copied, omit the SELECT statement.

View solution in original post

7 REPLIES 7
maguiremq
SAS Super FREQ

Do you have access to the XLSX engine? It makes it easy to do what you want, if I'm understanding your question correctly.

 

https://blogs.sas.com/content/sasdummy/2015/05/20/using-libname-xlsx-to-read-and-write-excel-files/

PaigeMiller
Diamond | Level 26

If your problem is just those three SAS data sets, then use this:

 

proc export 
  data=aa.suppae
  dbms=xlsx 
  outfile="C:/output/test.xlsx" 
  replace;
  sheet='Suppae';
run;

and repeat three times, changing the file and sheet name as appropriate. Remove the "replace" option on the 2nd and 3rd repeat.

--
Paige Miller
abraham1
Obsidian | Level 7
Thank you so much. Its working fine. As I have more dataset, I want the whole code to convert into macro. I am not that much expert in macro. The below code is not working. Can you please help one more time.

%macro export(supp);
proc export
data=aa.&supp
dbms=xlsx
outfile="C:/output/test.xlsx"
replace;
sheet=&supp;
run;
%mend;
%export(suppds)
PaigeMiller
Diamond | Level 26

No need to jump into the complexities of writing a macro.

 

As in many similar cases, people want to use macros when they are unnecessary. @Kurt_Bremser shows how to do this without macros.

--
Paige Miller
Kurt_Bremser
Super User

Use a LIBNAME, and PROC COPY:

libname aa 'C:/supp';
libname xlout xlsx "C:/output/test.xlsx";

proc copy in=aa out=xlout;
select
  suppae
  suppdm
  suppds
;
run;

libname xlout clear;

If you want all datasets in the library to be copied, omit the SELECT statement.

abraham1
Obsidian | Level 7
Thank you so much. Its working fine getting waring message for every dataset
'WARNING: Labels exceeding length 32 are not supported by engine XLSX and are being truncated'
Is it ok?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 7 replies
  • 1563 views
  • 6 likes
  • 4 in conversation