简体   繁体   中英

SAS- how to PROC EXPORT multiple PROC FREQ created by a macro?

I have a macro which looks like this:

%macro mac_name (st, en=); 
  %do j=1 %to &en.;
  %let k=%eval(&j.+1);
      proc freq data=data_name;
        tables status&j. * status&k. / nocol norow nopercent missing;
      run;
  %end;
%mend;
%mac_name (st=1, en=%sysfunc(week(%sysfunc(today()), u)));

The output produces multiple proc freq tables with the same title. I need this output put into a excel spreadsheet. Ideally all proc freqs in one sheet, one above the other or separate sheets.

Is this possible?

Thanks in advance!!!

The easiest way to do this is to use ODS EXCEL , if you have SAS 9.4.

ods excel file="yourfilename.xlsx";
proc freq data=sashelp.class;
  tables age;
run;

proc freq data=sashelp.class;
  tables sex;
run;
ods excel close;

You have options for whether they're all on one sheet or separate sheets. You can use ODS TAGSETS.EXCELXP if you have an earlier version of SAS, though they're less "true excel" files. You can also make CSV files or various other things with ODS .

In your case you'd put the opening ODS EXCEL line before the first call of the macro (doesn't have to precede the definition of the macro) and then the ODS EXCEL CLOSE line after the last call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM