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:
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.