BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
H
Pyrite | Level 9 H
Pyrite | Level 9

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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; 

View solution in original post

3 REPLIES 3
Shmuel
Garnet | Level 18

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; 

Astounding
PROC Star

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:

 

http://blogs.sas.com/content/sastraining/2015/01/30/sas-authors-tip-getting-the-macro-language-to-pe...

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1479 views
  • 2 likes
  • 4 in conversation