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.

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 178 views
  • 0 likes
  • 2 in conversation