/******************************************************************/ /* eSUG Spring 2015 */ /* Techniques for Model Scoring - Sylvain Tremblay*/ /******************************************************************/ /* DEMO1 - The SCORE Procedure */ /* Save your parameter estimates in a table and use Proc SCORE to apply your estimated model to a scoring dataset */ proc reg data=datasrc.baseball outest=work.Reg_Parameters /*noprint*/; id name team league; YHat:model logSalary = nhits nruns nrbi nbb yrmajor crhits; run; quit; proc score data=datasrc.baseball_ToBeScored score=work.Reg_Parameters type=parms predict out=work.Reg_Pred; var nhits nruns nrbi nbb yrmajor crhits; run; /******************************************************************/ /* DEMO2 - The SCORE statement */ /* Non parametric model - no parameters to be saved in a table... */ proc tpspline data=datasrc.Measure; model y=(x1 x2); score data=datasrc.Measure_ToBeScored out=work.Spline_Pred; run; /******************************************************************/ /* DEMO3 - The STORE statement and the PLM procedure */ /* STORE statement saves all of the information needed to recreate, evaluate and score the model */ proc logistic data=datasrc.Titanic; class Gender(ref='male') Class(ref='3') / param=ref; model Survived(event='1')=Age|Gender|Class @2 / selection=backward clodds=pl slstay=0.01; units age=10; store eSUG.store_titanic; run; proc plm source=eSUG.store_titanic; show all; run; proc plm source=eSUG.store_titanic; effectplot slicefit(x=age plotby=class); run; proc plm restore=eSUG.store_titanic; score data=datasrc.Titanic_ToBeScored out=work.Titanic_Pred /ilink; /* predicted values be inversely linked */ run; /******************************************************************/ /* DEMO4 - The CODE statement */ /* It writes DATA step statements into a text file You can then use the %INCLUDE statement to insert those statements into a DATA step */ proc logistic data=datasrc.Titanic noprint; class Gender(ref='male') Class(ref='3') / param=ref; model Survived(event='1')=Age|Gender|Class @2 / selection=backward clodds=pl slstay=0.01; units age=10; code file='Logistic_Scoring_Code.sas'; run; data work.Titanic_Pred_2; set datasrc.Titanic_ToBeScored; %include 'Logistic_Scoring_Code.sas'; run;