Varlist List for Repeating Procedure

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 109
Accepted Solution

Varlist List for Repeating Procedure

[ Edited ]

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;

 


Accepted Solutions
Solution
‎11-10-2016 12:59 PM
Super User
Posts: 1,244

Re: Varlist List for Repeating Procedure

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


All Replies
Solution
‎11-10-2016 12:59 PM
Super User
Posts: 1,244

Re: Varlist List for Repeating Procedure

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; 

Respected Advisor
Posts: 4,998

Re: Varlist List for Repeating Procedure

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...

 

 

Grand Advisor
Posts: 17,427
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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