Hi there,
I would like to persist the model (formula) produced by proc glmselect like so:
PROC GLMSELECT DATA = WORK.Training TESTDATA = WORK.Test; class AW LN PM(ref="FP"); MODEL Q = FN DR AW LN PM / selection = none stb showpvalues; ods output "Fit Statistics" = WORK.Model_Fit "Parameter Estimates" = WORK.ParameterEstimates Nobs = WORK.Nobs; RUN;
A cumbersome way would be to persits and parse the parameters in WORK.ParameterEstimates and then create a dynamic datastep to apply the formula to unseen data.
Surely there must be a simpler way? Any feedback would be very much appreciated. Thanks a lot.
Christian
The blog post that Reeza mentions explains the STORE statement, which saves a model into a SAS "itemstore".
You can then use PROC PLM to score the model. See the blog for details and for links to documentation and papers.
The following example is a small modification of the code in the blog:
proc GLMSELECT data=sashelp.cars;
model msrp = Cylinders EngineSize Horsepower Length
MPG_City MPG_Highway Weight Wheelbase;
store work.ScoreExample; /* store the model */
quit;
/* selected model contains two explanatory variables:
Horsepower and Wheelbase */
data NewData;
Horsepower = 200; Wheelbase = 100; output;
Horsepower = 250; Wheelbase = 110; output;
Horsepower = 180; Wheelbase = 95; output;
run;
proc plm restore=work.ScoreExample;
score data=NewData out=Pred; /* evaluate the model on new data */
run;
proc print data=Pred labels;
run;
Thanks. I am aware of the SCORE statement but could you please provide some code top see how this would work in my described use case? Thanks.
Here is an overview of scoring models in SAS.
It depends a bit on your version but CODE is my current preference.
http://blogs.sas.com/content/iml/2014/02/19/scoring-a-regression-model-in-sas.html
The blog post that Reeza mentions explains the STORE statement, which saves a model into a SAS "itemstore".
You can then use PROC PLM to score the model. See the blog for details and for links to documentation and papers.
The following example is a small modification of the code in the blog:
proc GLMSELECT data=sashelp.cars;
model msrp = Cylinders EngineSize Horsepower Length
MPG_City MPG_Highway Weight Wheelbase;
store work.ScoreExample; /* store the model */
quit;
/* selected model contains two explanatory variables:
Horsepower and Wheelbase */
data NewData;
Horsepower = 200; Wheelbase = 100; output;
Horsepower = 250; Wheelbase = 110; output;
Horsepower = 180; Wheelbase = 95; output;
run;
proc plm restore=work.ScoreExample;
score data=NewData out=Pred; /* evaluate the model on new data */
run;
proc print data=Pred labels;
run;
Hi Rick,
Thanks this works great in isolation but for some unexplainable reason not for my ecxample, which is inside a macro:
PROC GLMSELECT DATA = WORK.Training TESTDATA = WORK.Test; class AW LN PM(ref="FP"); MODEL Q = FN DR AW LN PM / selection = none stb showpvalues; store work.ScoreExample; ods output "Fit Statistics" = WORK.Model_Fit "Parameter Estimates" = WORK.ParameterEstimates Nobs = WORK.Nobs; RUN;
When I say it does not work, I cannot see a dataset work.ScoreExample. Any ideas?
As discussed in the blog post, the model is not stored in a data set. It is stored in an ITEM STORE. Item stores are explained on p. 3 and p. 6 of the Tobias and Cai (2010) paper that is linked to in the blog post. As it says on p. 6 of Tobias and Cai, you can use the SHOW statement in PROC PLM to display an item store.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.