Let us say I have a dataset like so:
ID X1 X2
1 1 1
2 1 0
Here Id indicates something to be modeled. The 0 and 1 in columns X1 and X2 indicate whether the indepedent varible should be used in the model (0=do not include, 1=include). So the model code to be produced would be:
PROC GLMSELECT data=TrainingData; model DependentVariable = X1 X2 / selection = stepwise(select=SL choose=AICC); run;
and
PROC GLMSELECT data=TrainingData; model DependentVariable = X1 / selection = stepwise(select=SL choose=AICC); run
respectivley. Ideally I would like to invoke a macro given the Id. The Id is then used to write and execute the modeling code. Btw the relvantTrainingData given Id can be easily initialised from anothe dataset. Any ideas how to achieve the above? Thanks!
If you are planning to use CALL EXECUTE, you don't really need to define a macro. Here's one way:
data _null_;
set have;
call execute('PROC GLMSELECT data=TrainingData;') ;
call execute('model Dependentvariable =') ;
array indeps {*} X1 X2 and a bunch more;
do _n_=1 to dim(indeps);
if indeps{_n_} = 1 then do;
varname = vname(indeps{_n_});
call execute(varname);
end;
end;
call execute ('/ selection = stepwise(select=SL choose=AICC); run;') ;
run;
Obviously it's untested, so it might need to be debugged.
1. Create a macro for your regression that takes a variable list
2. In the data step, create a variable that has the values you need, ie
ID X1 X2 Variable_List
1 1 1 X1 X2
2 1 0 X1
3. Pass those to the macro using CALL EXECUTE
If you are planning to use CALL EXECUTE, you don't really need to define a macro. Here's one way:
data _null_;
set have;
call execute('PROC GLMSELECT data=TrainingData;') ;
call execute('model Dependentvariable =') ;
array indeps {*} X1 X2 and a bunch more;
do _n_=1 to dim(indeps);
if indeps{_n_} = 1 then do;
varname = vname(indeps{_n_});
call execute(varname);
end;
end;
call execute ('/ selection = stepwise(select=SL choose=AICC); run;') ;
run;
Obviously it's untested, so it might need to be debugged.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: