BookmarkSubscribeRSS Feed
petlove
Obsidian | Level 7

Hi,

 

I am trying to create one excel file with different sheets for each dataset by using proc export. Following is my macro:

 

%macro export;


libname output "XXXXX";

 

%let domains=AE#DM;


%do i = 1 %to %eval(%sysfunc(count(&domains,#))+1);
%let dsn=%scan(&domains,&i,#);

 

proc export data=&dsn label
dbms=xlsx
outfile="test.xlsx"
replace;
;
sheet="&dsn.out" ;
run;

 

libname output;

 

%end;

%mend;

 

options merror serror symbolgen mlogic;
%export;

 

This macro overrides the existing sheet of AE.

 

Please let me know how to not override the previous sheet or append these sheets.

 

Thank you.

4 REPLIES 4
cau83
Pyrite | Level 9

Use "options mprint symbolgen;" as well as some %put statements to check the values of those parameters and see what is happening in each iteration of hte loop. It looks to me like the sheet names it would write out would be AEout.

PeterClemmensen
Tourmaline | Level 20

You can add the SHEET= along with the REPLACE option to your PROC EXPORT step.

petlove
Obsidian | Level 7

I already have SHEET= option in macro

Ksharp
Super User

libname x xlsx 'c:\temp\want.xlsx' ;

or

libname x excel 'c:\temp\want.xlsx';

 

proc copy in=work out=x;

select ae stdm;

run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 763 views
  • 0 likes
  • 4 in conversation