Admittedly, I always forget the answer to this question and have to search through old code.
Question: How do I create a list of variables to run one at a time through a procedure.
I want to run the below piece of code once for each individual variable. So it will run 23 models.
Y= Dependent Variable
X1-X23: Independent Variables
PROC LOGISTIC DATA = Dataset_Name ALPHA=0.002;
CLASS Y;
MODEL Y (EVENT="1") = X1 / LACKFIT FIRTH;
RUN;
Do it with a macro:
%macro run_model;
%do i=1 %to 23;
PROC LOGISTIC DATA = Dataset_Name ALPHA=0.002;
CLASS Y;
MODEL Y (EVENT="1") = X&i / LACKFIT FIRTH;
RUN;
%end;
%mend run_model;
%run_model;
Do it with a macro:
%macro run_model;
%do i=1 %to 23;
PROC LOGISTIC DATA = Dataset_Name ALPHA=0.002;
CLASS Y;
MODEL Y (EVENT="1") = X&i / LACKFIT FIRTH;
RUN;
%end;
%mend run_model;
%run_model;
This works very well when your variable names are actually X1 - X23. However, you have to code it differently if you have other names and would call a macro using:
%do_them_all (varlist=a long list of many variable names)
Here's a way to approach that problem:
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.