Programming the statistical procedures from SAS

persist fitted model produced by proc glmselect

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

persist fitted model produced by proc glmselect

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


Accepted Solutions
Solution
‎12-16-2016 11:26 AM
SAS Super FREQ
Posts: 3,315

Re: persist fitted model produced by proc glmselect

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


All Replies
Contributor
Posts: 42

Re: persist fitted model produced by proc glmselect

Contributor
Posts: 71

Re: persist fitted model produced by proc glmselect

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.

Grand Advisor
Posts: 16,908

Re: persist fitted model produced by proc glmselect

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

Contributor
Posts: 71

Re: persist fitted model produced by proc glmselect

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!
Solution
‎12-16-2016 11:26 AM
SAS Super FREQ
Posts: 3,315

Re: persist fitted model produced by proc glmselect

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;

 

Contributor
Posts: 71

Re: persist fitted model produced by proc glmselect

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?

 

 

 

SAS Super FREQ
Posts: 3,315

Re: persist fitted model produced by proc glmselect

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.

 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 141 views
  • 3 likes
  • 4 in conversation