Creates DATA step statements to compute the predicted values of a model that you create using the SEVERITY procedure.
specifies the name of the parameter estimations output data. This data set is created when you specify the OUTEST= option in the PROC SEVERITY statement.
specifies the name of the model information output data set. This data set is created when you specify the OUTMODELINGINFO= option in the PROC SEVERITY statement.
specifies the fileref that defines the location of the macro output files.
| Default | The SAS log |
specifies a prefix for the predicted dependent variable. The variable is named in the PROC SEVERITY LOSS= statement. When is prefix is applied to the dependent variable, this new name becomes the prediction variable.
| Default | P_ |
%let MyProj = C:\Users\myID;
%let MyProj = C:\MyJob\Projects;
libname Severity "&MyProj.\Severity\Test";
data Severity.phf;
/* Regression Coefficient for the Intercept Term */
retain fIntercept 6.8024;
/* Regression Coefficient for continuous AgeDriver */
retain fAgeDriver 0.01234;
/* Regression Coefficient for the three dummy indicators for nominal CarType */
retain fCarType_SEDAN 0;
retain fCarType_SPORT 1.0;
retain fCarType_TRUCK 0.5;
/* Regression Coefficient for the two dummy indicators for nominal Gender */
retain fGender_Female -1.5;
retain fGender_Male 0;
/* Regression Coefficient for the two dummy indicators for nominal HomeOwner */
retain fHomeOwner_NO 0;
retain fHomeOwner_YES 0.7;
/* Regression Coefficient for continuous IS */
retain fIS -0.00456;
/* Regression Coefficient for continuous MileageDriven */
retain fMileageDriven 0.013579;
/* Variable Labels */
label AgeDriver = 'Age of Driver';
label AmountLoss = 'Amount of Loss in Dollars';
format AmountLoss dollar.;
label CarType_SEDAN = 'Indicator of Car Type is Sedan';
label CarType_SPORT = 'Indicator of Car Type is Sport';
label CarType_TRUCK = 'Indicator of Car Type is Truck';
label EExp = 'Earned Exposure in Units of One Year';
label ExpYr = 'Exposure Year';
label Gender_Female = 'Indicator of Gender is Female';
label Gender_Male = 'Indicator of Gender is Male';
label HomeOwner_NO = 'Indicator of Home Ownership is No';
label HomeOwner_YES = 'Indicator of Home Ownership is Yes';
label IS = 'Insurance Score of Driver';
label MileageDriven = 'Mileage Driven in Units of 1,000 Miles';
label PolicyId = 'Policy Identifier';
call streaminit(27513);
do PolicyId = 00001 to 99999;
StartYr = 2000 +
rand('table', 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1);
do ExpYr = StartYr to 2011;
EExp = rand('uniform');
AgeDriver = 18 + rand('binomial',0.375, 72);
CarType_SEDAN = 0;
CarType_SPORT = 0;
CarType_TRUCK = 0;
select (rand('table', 0.4999, 0.2999, 0.1999, 0.0003));
when (1) CarType_SEDAN = 1;
when (2) CarType_SPORT = 1;
when (3) CarType_TRUCK = 1;
otherwise
do;
CarType_SEDAN = .;
CarType_SPORT = .;
CarType_TRUCK = .;
end;
end;
Gender_Female = 0;
Gender_Male = 0;
if (EExp lt 0.4999) then Gender_Female = 1;
else if (EExp lt 0.9999) then Gender_Male = 1;
else
do;
Gender_Female = .;
Gender_Male = .;
end;
HomeOwner_NO = 0;
HomeOwner_YES = 0;
if (rand('bernoulli', 0.25) eq 1) then HomeOwner_YES = 1;
else HomeOwner_NO = 1;
IS = round(rand('gamma', 600));
if (IS gt 800) then IS = 800;
else if (IS lt 1) then IS = 1;
MileageDriven = rand('gamma', 12);
/* Annual Mileage Driven in unit of 1000 miles */
if (nmiss(MileageDriven,AgeDriver,CarType_SEDAN,CarType_TRUCK,
CarType_SPORT,
Gender_Male,Gender_Female,
HomeOwner_YES,HomeOwner_NO,IS) eq 0)
then
do;
mu = fIntercept
+ fAgeDriver * (28 - AgeDriver)
+ fCarType_SEDAN * CarType_SEDAN + fCarType_SPORT
* CarType_SPORT
+ fCarType_TRUCK * CarType_TRUCK
+ fGender_Female * Gender_Female + fGender_Male
* Gender_Male
+ fHomeOwner_NO * HomeOwner_NO + fHomeOwner_YES
* HomeOwner_YES
+ fIS * IS
+ fMileageDriven * (MileageDriven - 12);
AmountLoss = exp(mu) * rand('gamma', 25);
end;
else AmountLoss = .;
output;
end;
end;
drop fAgeDriver fCarType_SEDAN fCarType_TRUCK fCarType_SPORT fGender_Male
fGender_Female fHomeOwner_YES fHomeOwner_NO fIntercept fIS fMileageDriven;
drop mu StartYr;
run;%let MyProj = C:\Users\emdev;
%let MyProj = C:\Users\minlam\Documents\Projects;
libname Severity "&MyProj.\Severity\Test";
title "SCALEMODEL and all applicable distributions";
%let model = 1;
%let predlist = AgeDriver CarType_SEDAN CarType_TRUCK CarType_SPORT
Gender_Male Gender_Female HomeOwner_YES HomeOwner_NO IS MileageDriven;
/* Build the model and obtain the required datasets */
proc severity data = Severity.phf
outest = Severity.ParamEst_&Model.
outmodelinfo = Severity.ModelInfo_&model.;
loss AmountLoss;
dist _predefined_ stweedie;
scalemodel &predlist.;
nloptions maxiter = 1000;
run;
/* Define the fileref for the output syntax */
filename ThisFile "&MyProj.\Severity\Test\ScoreCode_&Model..sas";
/* Invoke the macro */
%mm_severity_create_scorecode
(
ParamEst = Severity.ParamEst_&Model.,
ModelInfo = Severity.ModelInfo_&model.,
FileRef = ThisFile,
PredPrefix = MyPred_,
);
/* Execute the score codes within a DATA STEP */
data Severity.phf_wPrediction;
set Severity.phf;
%include ThisFile;
run;
proc contents data = Severity.phf_wPrediction;
run;
/**********************************************************************/ /* Begin scoring code for SEVERITY */ /* Created By: emdev */ /* Date: May 15, 2013 */ /* Time: 12:06:28 */ /**********************************************************************/ LENGTH _WARN_ $ 4; _WARN_ = ' '; LABEL _WARN_ = "Warnings" ; _nInputMiss = 0; /**********************************************************************/ /* Check the SCALEMODEL regression variables */ /**********************************************************************/ IF ( MISSING( MileageDriven ) EQ 1 ) THEN _nInputMiss = _nInputMiss + 1; IF ( MISSING( IS ) EQ 1 ) THEN _nInputMiss = _nInputMiss + 1; /* NOTE: HomeOwner_NO is not checked for missing values because it is a redundant regressor. */ IF ( MISSING( HomeOwner_YES ) EQ 1 ) THEN _nInputMiss = _nInputMiss + 1; IF ( MISSING( Gender_Female ) EQ 1 ) THEN _nInputMiss = _nInputMiss + 1; /* NOTE: Gender_Male is not checked for missing values because it is a redundant regressor. */ IF ( MISSING( CarType_SPORT ) EQ 1 ) THEN _nInputMiss = _nInputMiss + 1; IF ( MISSING( CarType_TRUCK ) EQ 1 ) THEN _nInputMiss = _nInputMiss + 1; /* NOTE: CarType_SEDAN is not checked for missing values because it is a redundant regressor. */
IF ( MISSING( AgeDriver ) EQ 1 ) THEN _nInputMiss = _nInputMiss + 1; /**********************************************************************/ /* Calculate scores only if current record contains valid values */ /**********************************************************************/ IF ( _nInputMiss EQ 0 ) THEN DO; /**********************************************************************/ /* Distribution: BURR */ /**********************************************************************/ _XBETA_ = 0; _XBETA_ = _XBETA_ + 1.344413338897300E-02 * MileageDriven ; _XBETA_ = _XBETA_ - 4.570022585401000E-03 * IS ; /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 7.004995716974000E-01 * HomeOwner_YES ; _XBETA_ = _XBETA_ - 1.499608973328200E+00 * Gender_Female ; /* NOTE: Gender_Male is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 9.997068084571000E-01 * CarType_SPORT ; _XBETA_ = _XBETA_ + 4.992376225576000E-01 * CarType_TRUCK ; /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ - 1.240862927421100E-02 * AgeDriver ; /* NOTE: MyPred_AmountLoss_BURR = GAMMA(1 + 1/Gamma) * GAMMA(Alpha - 1/Gamma) / GAMMA(Alpha) * Theta * EXP(_XBETA_) */ MyPred_AmountLoss_BURR = 2.729080537097400E+04 * EXP(_XBETA_); /**********************************************************************/ /* Distribution: EXP */ /**********************************************************************/ _XBETA_ = 0; _XBETA_ = _XBETA_ + 1.344997925413300E-02 * MileageDriven ; _XBETA_ = _XBETA_ - 4.570912461736200E-03 * IS ; /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 7.006247728147500E-01 * HomeOwner_YES ; _XBETA_ = _XBETA_ - 1.499520049919700E+00 * Gender_Female ; /* NOTE: Gender_Male is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 9.998154659889200E-01 * CarType_SPORT ; _XBETA_ = _XBETA_ + 4.991760040523900E-01 * CarType_TRUCK ; /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ - 1.240552808055000E-02 * AgeDriver ; /* NOTE: MyPred_AmountLoss_EXP = 1 * Theta * EXP(_XBETA_) */ MyPred_AmountLoss_EXP = 2.730403090782800E+04 * EXP(_XBETA_); /**********************************************************************/ /* Distribution: GAMMA */ /**********************************************************************/ _XBETA_ = 0; _XBETA_ = _XBETA_ + 1.344997933121800E-02 * MileageDriven ; _XBETA_ = _XBETA_ - 4.570912459089100E-03 * IS ; /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 7.006247729158700E-01 * HomeOwner_YES ; _XBETA_ = _XBETA_ - 1.499520049929900E+00 * Gender_Female ; /* NOTE: Gender_Male is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 9.998154662540800E-01 * CarType_SPORT ; _XBETA_ = _XBETA_ + 4.991760039384900E-01 * CarType_TRUCK ; /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ - 1.240552804902500E-02 * AgeDriver ; /* NOTE: MyPred_AmountLoss_GAMMA = Alpha * Theta * EXP(_XBETA_) */ MyPred_AmountLoss_GAMMA = 2.730405549354900E+04 * EXP(_XBETA_);
/**********************************************************************/ /* Distribution: GPD */ /**********************************************************************/ _XBETA_ = 0; _XBETA_ = _XBETA_ + 1.345090198095600E-02 * MileageDriven ; _XBETA_ = _XBETA_ - 4.569987445112400E-03 * IS ; /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 7.006260117108500E-01 * HomeOwner_YES ; _XBETA_ = _XBETA_ - 1.499518185889600E+00 * Gender_Female ; /* NOTE: Gender_Male is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 9.998173115643000E-01 * CarType_SPORT ; _XBETA_ = _XBETA_ + 4.991779592407300E-01 * CarType_TRUCK ; /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ - 1.240306956097400E-02 * AgeDriver ; /* NOTE: MyPred_AmountLoss_GPD = 1 / (1 - Xi) * Theta * EXP(_XBETA_) */ MyPred_AmountLoss_GPD = 2.728530960810300E+04 * EXP(_XBETA_); /**********************************************************************/ /* Distribution: IGAUSS */ /**********************************************************************/ _XBETA_ = 0; _XBETA_ = _XBETA_ + 1.344333259472700E-02 * MileageDriven ; _XBETA_ = _XBETA_ - 4.572143035437300E-03 * IS ; /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 7.006130278360900E-01 * HomeOwner_YES ; _XBETA_ = _XBETA_ - 1.499413162869200E+00 * Gender_Female ; /* NOTE: Gender_Male is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 9.997768449055400E-01 * CarType_SPORT ; _XBETA_ = _XBETA_ + 4.991467916958200E-01 * CarType_TRUCK ; /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ - 1.241894446056000E-02 * AgeDriver ; /* NOTE: MyPred_AmountLoss_IGAUSS = 1 * Theta * EXP(_XBETA_) */ MyPred_AmountLoss_IGAUSS = 2.734200065401500E+04 * EXP(_XBETA_); /**********************************************************************/ /* Distribution: LOGN */ /**********************************************************************/ _XBETA_ = 0; _XBETA_ = _XBETA_ + 1.344165732039300E-02 * MileageDriven ; _XBETA_ = _XBETA_ - 4.571943993968500E-03 * IS ; /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 7.006057373962000E-01 * HomeOwner_YES ; _XBETA_ = _XBETA_ - 1.499427525786600E+00 * Gender_Female ; /* NOTE: Gender_Male is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 9.997737501240600E-01 * CarType_SPORT ; _XBETA_ = _XBETA_ + 4.991635085860000E-01 * CarType_TRUCK ; /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ - 1.241995587270100E-02 * AgeDriver ; /* NOTE: MyPred_AmountLoss_LOGN = EXP(Sigma*Sigma/2) * EXP(Mu) * EXP(_XBETA_) */ MyPred_AmountLoss_LOGN = 2.734808258530300E+04 * EXP(_XBETA_);
/**********************************************************************/ /* Distribution: PARETO */ /**********************************************************************/ _XBETA_ = 0; _XBETA_ = _XBETA_ + 1.344702841631400E-02 * MileageDriven ; _XBETA_ = _XBETA_ - 4.573870525107900E-03 * IS ; /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 7.006208104018000E-01 * HomeOwner_YES ; _XBETA_ = _XBETA_ - 1.499526007562500E+00 * Gender_Female ; /* NOTE: Gender_Male is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 9.998095632861300E-01 * CarType_SPORT ; _XBETA_ = _XBETA_ + 4.991697518801100E-01 * CarType_TRUCK ; /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ - 1.241339040886400E-02 * AgeDriver ; /* NOTE: MyPred_AmountLoss_PARETO = 1 / (Alpha - 1) * Theta * EXP(_XBETA_) */ MyPred_AmountLoss_PARETO = 2.736400276713000E+04 * EXP(_XBETA_); /**********************************************************************/ /* Distribution: STWEEDIE */ /**********************************************************************/ _XBETA_ = 0; _XBETA_ = _XBETA_ + 1.345898239828500E-02 * MileageDriven ; _XBETA_ = _XBETA_ - 4.570041179676800E-03 * IS ; /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 7.006207334939600E-01 * HomeOwner_YES ; _XBETA_ = _XBETA_ - 1.499496885374900E+00 * Gender_Female ; /* NOTE: Gender_Male is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 9.998043617045600E-01 * CarType_SPORT ; _XBETA_ = _XBETA_ + 4.991607418998200E-01 * CarType_TRUCK ; /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ - 1.239129336545400E-02 * AgeDriver ; /* NOTE: MyPred_AmountLoss_STWEEDIE = Lambda * (2 - P) / (P - 1) * Theta * EXP(_XBETA_) */ MyPred_AmountLoss_STWEEDIE = 2.726265339822600E+04 * EXP(_XBETA_); /**********************************************************************/ /* Distribution: WEIBULL */ /**********************************************************************/ _XBETA_ = 0; _XBETA_ = _XBETA_ + 1.350103959448200E-02 * MileageDriven ; _XBETA_ = _XBETA_ - 4.569462924201300E-03 * IS ; /* NOTE: HomeOwner_NO is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 7.007182928623600E-01 * HomeOwner_YES ; _XBETA_ = _XBETA_ - 1.499697786981000E+00 * Gender_Female ; /* NOTE: Gender_Male is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ + 1.000109511872200E+00 * CarType_SPORT ; _XBETA_ = _XBETA_ + 4.989436512356800E-01 * CarType_TRUCK ; /* NOTE: CarType_SEDAN is skipped because it is a redundant regressor. */ _XBETA_ = _XBETA_ - 1.233857684563600E-02 * AgeDriver ; /* NOTE: MyPred_AmountLoss_WEIBULL = GAMMA(1 + 1/Tau) * Theta * EXP(_XBETA_) */ MyPred_AmountLoss_WEIBULL = 2.707248194039600E+04 * EXP(_XBETA_); END;
ELSE DO; /**********************************************************************/ /* Set _WARN_ value */ /**********************************************************************/ SUBSTR(_WARN_,1,1) = 'M'; END; LABEL MyPred_AmountLoss_BURR = "Predicted Mean for the Burr Distribution" ; LABEL MyPred_AmountLoss_EXP = "Predicted Mean for the Exponential Distribution" ; LABEL MyPred_AmountLoss_GAMMA = "Predicted Mean for the Gamma Distribution" ; LABEL MyPred_AmountLoss_GPD = "Predicted Mean for the Generalized Pareto Distribution" ; LABEL MyPred_AmountLoss_IGAUSS = "Predicted Mean for the Inverse Gaussian Distribution" ; LABEL MyPred_AmountLoss_LOGN = "Predicted Mean for the Lognormal Distribution" ; LABEL MyPred_AmountLoss_PARETO = "Predicted Mean for the Pareto Distribution" ; LABEL MyPred_AmountLoss_STWEEDIE = "Predicted Mean for the Tweedie Distribution with Scale Parameter" ; LABEL MyPred_AmountLoss_WEIBULL = "Predicted Mean for the Weibull Distribution" ; DROP _nInputMiss _XBETA_; /**********************************************************************/ /* End scoring code for SEVERITY */ /**********************************************************************/






