1
votes

I have a list of variables that need to be run in a SAS macro.

%let var= 
A10Y
B2D
C112D
D
ER
RT
DDS
AQWE
DA

And I have a macro like this:
%macro st(inputx);
proc means data = suy;
var &inputx.;
run;
%mend;

I want to write a loop because if the number of variables are bigger than 100, I don't want to specify them one by one.

1
Why not call them all at once in the VAR statement? Going over the output for 100+ variables is also silly so I'm guessing this isn't the whole question. Perhaps more details will help.Reeza
The function I use in macro is not like proc means, some very complex function that can't simply use &var together. proc means is just a example.Elif Y

1 Answers

2
votes

OK. I wouldn't use macro, I'd use call execute.

Create a dataset to hold all your variable lists or whatever then do the following:

*Create list of variables;
proc sql;
    create table var_list as
    select name 
    from sashelp.vcolumn
    where libname='SASHELP' 
        and memname='CLASS' 
        and type='num';
run;

*Create macro;
%macro st(inputx);
    proc means data = sashelp.class;
        var &inputx.;
    run;
%mend;

*Call macro using call execute;
data _null_;
    set var_list;
    call execute ("%st("||name||");");
run;