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;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.