Yes, the program can be used inside a macro using loop to reference multiple variables sequentially.
See the below example which creates a macro parameter 'freqvars' referencing to multiple variables, then creates a macro variable 'freqvar' referencing to an individual variable (out of multiple variables) and processes each variable in a loop in the order they are referenced in macro parameter (freqvars=). This macro creates datasets for each variable with frequency of categories.
%macro freqs(freqvars=);
%do i= 1 %to %sysfunc(countw(&freqvars));
%let freqvar= %scan(&freqvars, &i);
data have1;
set have;
num= countc(&freqvar, ',');
if num=0 then do;
Services= strip(&freqvar);
output;
end;
else do i=1 to num+1;
Services= scan(&freqvar, i, ',');
output;
end;
run;
proc freq data=have1;
tables services/nocol norow nocum out=&freqvar(rename=(count=n));
run;
%end;
%mend;
%freqs(freqvars= Referral_Sevice VAR2 VAR3 ... VARn);
... View more