I am running a regression on var_x versus var_y in a calibration step. In a later step I want to use the outcome of this regression as a variable in my code.
For now I am running the regression and afterwards copy the results manually in my code.
The calibration step is as follows:
proc reg data = mydata;
model x_var = y_var;
run;
The output of this regression looks like this:
In a later step I manually copy the values in my code:
data myImpacts;
set impactdatabase;
new_y_var_2 = 0.08014 + 0.68315 * y_var2;
run;
As my input database changes often, I would like to automate the manual feeding of the two parameters in this last step.
Thank you!
Use the outest
option of proc reg
to save your parameter estimates to a dataset. For example:
proc reg data = sashelp.cars outest=outest noprint;
new_y_var_2: model horsepower = msrp;
run;
This produces the following:
_MODEL_ _TYPE_ _DEPVAR_ _RMSE_ Intercept MSRP Horsepower
new_y_var_2 PARMS Horsepower 40.439546195 115.68993159 0.003057087 -1
Now you have two options:
- Save the coefficients in macro variables and run it through a DATA step
- Use PROC SCORE to score your data
Option 1: Saving macro variables
This will work, but is a bit more manual because you need to specify each coefficient that you want to save into a macro variable, then specify it again. It’s not ideal.
data _null_;
set outest;
call symputx('int', intercept);
call symputx('msrp', msrp);
run;
data myimpacts;
set sashelp.cars;
new_y_var_2 = &int + &msrp*msrp;
run;
Option 2: PROC SCORE
PROC SCORE is designed to do exactly what you’re trying to do. It takes an input dataset, some parameter estimates, and it scores the data. You don’t need to create any macro variables.
proc score data = sashelp.cars
score = outest
out = myimpacts
type = parms;
var msrp;
run;
new_y_var_2
228.63400951
188.5097431
198.20070877
217.16993339
249.45277174
...