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.

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