BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello friends ,

I have train data, test data, out of time data.

There are 3 things I want to do-

1-calculate model coefficients based on train data 

2-calculate pred valued for each observation train+test data

3-calculate pred valued for each observation in out of time data

 

What is the way to perform task 3 using proc genmod ?

 

Please note that I tried to save the coefficients in a permanents data set (permanent  library) but I cannot find this data set

proc genmod data=panel;
ods output parameterestimates=tbl_coefficients;/****Data set with Coeficients information that was calculated from train data only****/
weight weight;
model y=x / dist=binomial link=logit  type3 wald ;
output out=preds_tbl pred=P_BAD XBETA=logit;
store R_R.coefficients;
Run;

 

 


Data train(KEEP=X Y);
Do i=1 to 50;
x=ranuni(1234579);
p = 0.6;
u = rand("Uniform");
if (u < p) then Y=1;else Y=0;
output;
end;
Run;


Data test(KEEP=X Y);
Do i=1 to 25;
x=ranuni(1234579);
p = 0.6;
u = rand("Uniform");
if (u < p) then Y=1;else Y=0;
output;
end;
Run;

data panel;
set train(in=a) test(in=b);
if a then weight=1;else weight=0;/***Value 1 for train data, value 0 for test data**/
Run;


proc genmod data=panel;
ods output parameterestimates=tbl_coefficients;/****Data set with Coeficients information that was calculated from train data only****/
weight weight;
model y=x / dist=binomial link=logit  type3 wald ;
output out=preds_tbl pred=P_BAD XBETA=logit;
Run;



Data Out_of_time;
Do i=1 to 200;
x=ranuni(1234579);
p = 0.6;
u = rand("Uniform");
if (u < p) then Y=1;else Y=0;
output;
end;
Run;
/**I want to calculate pred on this data of out of time***/

 

 

 

4 REPLIES 4
Ksharp
Super User

1-calculate model coefficients based on train data 


Data train(KEEP=X Y);
Do i=1 to 50;
x=ranuni(1234579);
p = 0.6;
u = rand("Uniform");
if (u < p) then Y=1;else Y=0;
output;
end;
Run;


Data test(KEEP=X Y);
Do i=1 to 25;
x=ranuni(1234579);
p = 0.6;
u = rand("Uniform");
if (u < p) then Y=1;else Y=0;
output;
end;
Run;

data panel;
set train test;
Run;


proc genmod data=train;
ods output parameterestimates=tbl_coefficients;
model y=x / dist=binomial link=logit  type3 wald ;
 store PainModel ;
Run;

 

2-calculate pred valued for each observation train+test data


proc plm restore=PainModel;
   score data=panel out=Score_panel predicted LCLM UCLM / ilink; /* ILINK gives probabilities */
run;

3-calculate pred valued for each observation in out of time data


Data Out_of_time;
Do i=1 to 200;
x=ranuni(1234579);
p = 0.6;
u = rand("Uniform");
if (u < p) then Y=1;else Y=0;
output;
end;
Run;

proc plm restore=PainModel;
   score data=Out_of_time out=Score_Out_of_time predicted LCLM UCLM / ilink; /* ILINK gives probabilities */
run;
Ronein
Meteorite | Level 14
Thank you. Is it possible to save the coefficients in a permanent data set and then can use it in the future on any out of time data set to calculate predictions...??
Ksharp
Super User
In my code:
ods output parameterestimates=tbl_coefficients;

already save these estimated parameters into dataset named 'tbl_coefficients' .

"can use it in the future on any out of time data set to calculate predictions...??"
Sure, of course. The following is an example for scoring dataset PANEL:


proc transpose data=tbl_coefficients out=tbl_coefficients2 prefix=_;
var Estimate;
id Parameter;
run;
data score_panel2;
if _n_=1 then set tbl_coefficients2;
set panel;
y_hat=logistic(_intercept+_x*x);
run;
PaigeMiller
Diamond | Level 26

It's a lot easier if you use PROC LOGISTIC instead of PROC GENMOD. There doesn't seem to be a reason in your problem description that you would have to use GENMOD.

 

proc logistic data=train ... ;
    model y = x1 x2 ... ;
    score data=train out=trainpreds;
    score data=test out=testpreds;
    score data=outoftime out=outoftimepreds;
run;
--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 480 views
  • 0 likes
  • 3 in conversation