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;
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.