SAS beginner here. I made a macro that creates tables from datasets of different libraries (there is one library for each year). The proc tabulate part works fine. My problem is that I would like to export each table to one sheet within the same Excel file, and each sheet labeled with the macro variable "year". In the end I would like to have one Excel file with sheets named 20, 19, 18, 17, 16, 15 and 14.
I tried this by inserting an ods tagsets.excelxp command, as this is the export command that was also used throughout the rest of the syntax, which I "inherited".
The result is an Excel file with a single sheet named "&year." (not "14") and the data from the last macro call, year 14.
Does anybody know how this can be solved? Also, I would be glad for suggestions concerning a more elegant way than calling the macro 7 times. Like looping over a list of years or something.
%macro MyMacro (year = );
%local indsn;
%let indsn=path&year..myfile1;
ods tagsets.excelxp File='P:\Folder\Folder\Folder\MyMacro.xls' style=statistical options(sheet_name='&year.');
proc tabulate data=&indsn;
class var1 var2;
table var1 all, var2 all/printmiss;
title "var1 and var2, year: &year.";
run;
ods tagsets.excelxp close;
%mend MyMacro;
%MyMacro(year=20)
%MyMacro(year=19)
%MyMacro(year=18)
%MyMacro(year=17)
%MyMacro(year=16)
%MyMacro(year=15)
%MyMacro(year=14)