BookmarkSubscribeRSS Feed
dkanand86
Calcite | Level 5

Hi Everyone,

 

I want to export the results for each macro run into different sheets of same excel file. But, unable to get that kind of result.

 

Please help! Thanks!

 

 

 

Code is below:

 

rsubmit;

 

options compress=yes mprint symbolgen mlogic;

 

%macro cs_new2(base_dsn=,recent_dsn=,var_name=,n=);

 

ods tagsets.excelxp style=minimal file="location/cs_r_mod.xls";

 

ods tagsets.excelxp options(sheet_name="Sheet&n.");

 

/*ods html file="location/cs_&var_name._new.xls";*/

 

proc freq data=&base_dsn.;

table &var_name. /list missing out=base_&var_name. (rename=(percent=baseline_pct count=baseline_N));

run;

 

proc freq data=&recent_dsn.;

table &var_name./list missing out=recent_&var_name.(rename=(percent=recent_pct count=recent_N));

run;

 

ods tagsets.excelxp close;

 

%mend cs_new2;

 

endrsubmit;

 

 

rsubmit;

 

%cs_new2(base_dsn=sph_lds,recent_dsn=data_v1,var_name=VAR1,n=1);

%cs_new2(base_dsn=sph_lds,recent_dsn=data_v1,var_name=VAR2,n=2);

%cs_new2(base_dsn=sph_lds_dsn=data_v1,var_name=VAR3,n=3);

%cs_new2(base_dsn=sph_lds,recent_dsn=data_v1,var_name=VAR4,n=4);

%cs_new2(base_dsn=sph_lds,recent_dsn=data_v1,var_name=VAR5,n=5);

%cs_new2(base_dsn=sph_lds,recent_dsn=data_v1,var_name=VAR6,n=6);

 

 

 

endrsubmit;

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You have the line:

ods tagsets.excelxp style=minimal file="location/cs_r_mod.xls";

 

In your macro.  Everytime this code runs the file is created anew.  Put this line outside your macro calls:

ods tagsets.excelxp style=minimal file="location/cs_r_mod.xls";

%cs_new2(...);

%cs_new2(...);

ods tagsets.excelxp close;

 

Only change the sheet name in the macro.

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
  • 1 reply
  • 854 views
  • 0 likes
  • 2 in conversation