BookmarkSubscribeRSS Feed
lionking19063
Fluorite | Level 6

Hi, 

I wonder how to run models based on first N input variables from a list. For example, the list contains "age height weight BMI income" and I would like to fit a series of regression model based on first N variable. I can write them one by one, but wonder if there is a efficient way of doing it. Thank you in advanced.

model 1:
proc reg data=data;

model y=age;

run;

model 2:
proc reg data=data;

model y=age  height;

run;

model 3:
proc reg data=data;

model y=age height weight;

run;

model 4:

proc reg data=data;

model y=age height weight BMI;

run;

model 5:

proc reg data=data;

model y=age height weight BMI income;

run;

 

1 REPLY 1
ballardw
Super User

Where does your list reside?

With Proc Reg I think you are looking at macro language. Perhaps something like:

%macro reglist(varlist= );
   %let words=;
   proc reg data=data;

   %do i= 1 %to %sysfunc(countw(&varlist));
      %let words= &words %scan(&varlist,&i.);
      model&1.: model y=&words.;
/*optional Model&i statements here*/ %end; run; %mend; %reglist (varlist=age height weight BMI income);

Proc Reg will allow multiple model statements. If you are adding other optional statements then all of them related to a single model would have to appear before the next model statement. The bit before the model=, where I am using Model&i is a label that will have the text Model1, Model2, etc, depending on the number of variables used appearing in the output so you can tell which model the output is for.

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1 reply
  • 523 views
  • 0 likes
  • 2 in conversation