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

Hi guys, I would very much appreciate help with this. After extensive search I still haven't found an answer to my question so I'm turning to the community!

 

I'm running a regression (PROC REG) which selects only one variable from a list of predictors. I need to use the variable for later analysis. How can I access it/store it for later use? I tried using output tables but I don't know how to recognize which was the selected variable.

 

Thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

You can capture the output into a table and then push that to macro variables. There are other ways, but it does partly depend on what your next step will be and what form you need that list in.

 

Here's a fully worked example.

 

*model fit with selection method;
ods output SelectionSummary=list  SelParmEst=varListReg;
proc reg data=sashelp.cars;
model mpg_city = mpg_highway cylinders invoice msrp  /  selection=backward;
run;quit;

*save results to macro variable;
proc sql noprint;
select variable into :var_list separated by " "
from varListReg
having max(step)=step;
quit;

*test macro variable;
%put &var_list;

*illustrate usage;
data demo;
set sashelp.cars;
keep &var_list.;
run;


View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

Hi @km7 and welcome to the SAS Support Communities!

 

Insert the following statement before or into your PROC REG step:

ods output SelParmEst=est;

Now PROC REG should create an ODS output dataset EST (you may specify a different name) which contains a variable named "Variable" with the name of the selected model variable and 'Intercept' (unless you specified the NOINT option of the MODEL statement).

[Edit:] Look at the last observation of this dataset because it also contains information about earlier steps in the model selection process (see variable "Step").

Reeza
Super User

You can capture the output into a table and then push that to macro variables. There are other ways, but it does partly depend on what your next step will be and what form you need that list in.

 

Here's a fully worked example.

 

*model fit with selection method;
ods output SelectionSummary=list  SelParmEst=varListReg;
proc reg data=sashelp.cars;
model mpg_city = mpg_highway cylinders invoice msrp  /  selection=backward;
run;quit;

*save results to macro variable;
proc sql noprint;
select variable into :var_list separated by " "
from varListReg
having max(step)=step;
quit;

*test macro variable;
%put &var_list;

*illustrate usage;
data demo;
set sashelp.cars;
keep &var_list.;
run;


km7
Calcite | Level 5 km7
Calcite | Level 5

Thank you all for the fast and informative response! This is exactly what I was looking for Smiley Happy

Rick_SAS
SAS Super FREQ

Switch to PROC GLMSELECT and use the automatically generated macro variable (&_GLSInd) as described in the article "Which variables are in the final selected model?."

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 2502 views
  • 3 likes
  • 4 in conversation