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***/
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.