Reputation: 175
I'd like to improve a SAS macro that loops through some variables and prints frequency tables for them.
Here's the working macro:
%macro iraCatFreq(IRACatsList);
%local i next;
%let i=1;
%do i=1 %to %sysfunc(countw(&IRACatsList));
%let next=%scan(&IRACatsList,&i);
proc freq data=out.SCF16_Cath;
weight WGT;
by ANYPEN;
tables &next;
format rRothContrBin allBinaries_format.;
run;
%end;
%mend iraCatFreq;
%iraCatFrew(rRothContrBin sRothContrBin oRothContrBin rRegContrBin sRegContrBin oRegContrBin);
I wanted to improve this macro by replacing the parameter list of variable names (rRothContrBin sRothContrBin oRothContrBin rRegContrBin sRegContrBin oRegContrBin) with a single parameter.
Here's the approach I cobbled together:
/*Create a table of variable names for IRA types and owners*/
data IRACats;
infile datalines;
length x $ 17;
input x $;
datalines;
rRothContrBin
sRothContrBin
oRothContrBin
rRegContrBin
sRegContrBin
oRegContrBin
;
/*Convert table of strings into a macro variable, &IRACatsList */
proc sql noprint;
select x into :IRACatsList separated by ' '
from IRACats;
quit;
%put IRACatsList = &IRACatsList;
I tried running the macro after running this approach,
%iraCatFreq(&IRACatsList);
It works, but is there a better way to do this without the data and proc sql steps?
Upvotes: 0
Views: 148
Reputation: 540
You can call the existing macro with a single macro variable and without using proc sql or data steps like this:
%let IRACatsList = rRothContrBin sRothContrBin oRothContrBin rRegContrBin sRegContrBin oRegContrBin;
%iraCatFreq(&IRACatsList);
Upvotes: 2