BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
csetzkorn
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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;

 

View solution in original post

7 REPLIES 7
csetzkorn
Lapis Lazuli | Level 10

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.

Reeza
Super User

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

csetzkorn
Lapis Lazuli | Level 10
Thanks I am using version current version: 9.04.01M3P062415 and was aware of the quoted post. However, the outest option does not exist for PROC GLMSELECT IMHO. Some example code would be very much appreciated!
Rick_SAS
SAS Super FREQ

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;

 

csetzkorn
Lapis Lazuli | Level 10

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?

 

 

 

Rick_SAS
SAS Super FREQ

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.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 1745 views
  • 3 likes
  • 4 in conversation