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?

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