*************************************; *** begin scoring code for regression; *************************************; length _WARN_ $4; label _WARN_ = 'Warnings' ; length I_BAD $ 12; label I_BAD = 'Into: BAD' ; *** Target Values; array RGDRF [2] $12 _temporary_ ('1' '0' ); label U_BAD = 'Unnormalized Into: BAD' ; *** Unnormalized target values; ARRAY RGDRU[2] _TEMPORARY_ (1 0); *** Generate dummy variables for BAD ; drop _Y ; label F_BAD = 'From: BAD' ; length F_BAD $ 12; F_BAD = put( BAD , BEST12. ); %DMNORMIP( F_BAD ) if missing( BAD ) then do; _Y = .; end; else do; if F_BAD = '0' then do; _Y = 1; end; else if F_BAD = '1' then do; _Y = 0; end; else do; _Y = .; end; end; drop _DM_BAD; _DM_BAD=0; *** Check CLAG_K4W for missing values ; if missing( CLAG_K4W ) then do; substr(_warn_,1,1) = 'M'; _DM_BAD = 1; end; *** Check DEBTINC for missing values ; if missing( DEBTINC ) then do; substr(_warn_,1,1) = 'M'; _DM_BAD = 1; end; *** Check INDELINQ for missing values ; if missing( INDELINQ ) then do; substr(_warn_,1,1) = 'M'; _DM_BAD = 1; end; *** Check INDEROG for missing values ; if missing( INDEROG ) then do; substr(_warn_,1,1) = 'M'; _DM_BAD = 1; end; *** Check LOAN_9QB for missing values ; if missing( LOAN_9QB ) then do; substr(_warn_,1,1) = 'M'; _DM_BAD = 1; end; *** Check MORT_G0S for missing values ; if missing( MORT_G0S ) then do; substr(_warn_,1,1) = 'M'; _DM_BAD = 1; end; *** Check YOJ_34KW for missing values ; if missing( YOJ_34KW ) then do; substr(_warn_,1,1) = 'M'; _DM_BAD = 1; end; *** Generate dummy variables for JOB ; drop _2_0 _2_1 _2_2 _2_3 _2_4 ; *** encoding is sparse, initialize to zero; _2_0 = 0; _2_1 = 0; _2_2 = 0; _2_3 = 0; _2_4 = 0; if missing( JOB ) then do; _2_0 = .; _2_1 = .; _2_2 = .; _2_3 = .; _2_4 = .; substr(_warn_,1,1) = 'M'; _DM_BAD = 1; end; else do; length _dm7 $ 7; drop _dm7 ; %DMNORMCP( JOB , _dm7 ) _dm_find = 0; drop _dm_find; if _dm7 <= 'OTHER' then do; if _dm7 <= 'OFFICE' then do; if _dm7 = 'MGR' then do; _2_0 = 1; _dm_find = 1; end; else do; if _dm7 = 'OFFICE' then do; _2_1 = 1; _dm_find = 1; end; end; end; else do; if _dm7 = 'OTHER' then do; _2_2 = 1; _dm_find = 1; end; end; end; else do; if _dm7 <= 'SALES' then do; if _dm7 = 'PROFEXE' then do; _2_3 = 1; _dm_find = 1; end; else do; if _dm7 = 'SALES' then do; _2_4 = 1; _dm_find = 1; end; end; end; else do; if _dm7 = 'SELF' then do; _2_0 = -1; _2_1 = -1; _2_2 = -1; _2_3 = -1; _2_4 = -1; _dm_find = 1; end; end; end; if not _dm_find then do; _2_0 = .; _2_1 = .; _2_2 = .; _2_3 = .; _2_4 = .; substr(_warn_,2,1) = 'U'; _DM_BAD = 1; end; end; *** Generate dummy variables for NINQ_76F ; drop _3_0 _3_1 ; if missing( NINQ_76F ) then do; _3_0 = .; _3_1 = .; substr(_warn_,1,1) = 'M'; _DM_BAD = 1; end; else do; length _dm17 $ 17; drop _dm17 ; _dm17 = put( NINQ_76F , NINQ_T5_17. ); %DMNORMIP( _dm17 ) if _dm17 = '0001:LOW-0.5' then do; _3_0 = 1; _3_1 = 0; end; else if _dm17 = '0003:1.5-HIGH' then do; _3_0 = -1; _3_1 = -1; end; else if _dm17 = '0002:0.5-1.5' then do; _3_0 = 0; _3_1 = 1; end; else do; _3_0 = .; _3_1 = .; substr(_warn_,2,1) = 'U'; _DM_BAD = 1; end; end; *** If missing inputs, use averages; if _DM_BAD > 0 then do; _P0 = 0.2023079697; _P1 = 0.7976920303; goto RGDR1; end; *** Compute Linear Predictor; drop _TEMP; drop _LP0; _LP0 = 0; *** Effect: CLAG_K4W ; _TEMP = CLAG_K4W ; _LP0 = _LP0 + ( -0.78690764730093 * _TEMP); *** Effect: DEBTINC ; _TEMP = DEBTINC ; _LP0 = _LP0 + ( 0.06939430135677 * _TEMP); *** Effect: INDELINQ ; _TEMP = INDELINQ ; _LP0 = _LP0 + ( 1.60218107435311 * _TEMP); *** Effect: INDEROG ; _TEMP = INDEROG ; _LP0 = _LP0 + ( 1.36551647764982 * _TEMP); *** Effect: JOB ; _TEMP = 1; _LP0 = _LP0 + ( 0.02339994301053) * _TEMP * _2_0; _LP0 = _LP0 + ( -0.57526212520046) * _TEMP * _2_1; _LP0 = _LP0 + ( -0.0385300730656) * _TEMP * _2_2; _LP0 = _LP0 + ( 0.00059411038964) * _TEMP * _2_3; _LP0 = _LP0 + ( 0.49313841586884) * _TEMP * _2_4; *** Effect: LOAN_9QB ; _TEMP = LOAN_9QB ; _LP0 = _LP0 + ( -0.5320614549918 * _TEMP); *** Effect: MORT_G0S ; _TEMP = MORT_G0S ; _LP0 = _LP0 + ( -0.34740449441048 * _TEMP); *** Effect: NINQ_76F ; _TEMP = 1; _LP0 = _LP0 + ( -0.21792456211849) * _TEMP * _3_0; _LP0 = _LP0 + ( -0.17253416894202) * _TEMP * _3_1; *** Effect: YOJ_34KW ; _TEMP = YOJ_34KW ; _LP0 = _LP0 + ( -0.27770947608238 * _TEMP); *** Naive Posterior Probabilities; drop _MAXP _IY _P0 _P1; _TEMP = 9.15445900940893 + _LP0; if (_TEMP < 0) then do; _TEMP = exp(_TEMP); _P0 = _TEMP / (1 + _TEMP); end; else _P0 = 1 / (1 + exp(-_TEMP)); _P1 = 1.0 - _P0; RGDR1: *** Residuals; if (_Y = .) then do; R_BAD1 = .; R_BAD0 = .; end; else do; label R_BAD1 = 'Residual: BAD=1' ; label R_BAD0 = 'Residual: BAD=0' ; R_BAD1 = - _P0; R_BAD0 = - _P1; select( _Y ); when (0) R_BAD1 = R_BAD1 + 1; when (1) R_BAD0 = R_BAD0 + 1; end; end; *** Update Posterior Probabilities; *** Decision Processing; label D_BAD_ = 'Decision: BAD' ; label EP_BAD_ = 'Expected Profit: BAD' ; label BP_BAD_ = 'Best Profit: BAD' ; label CP_BAD_ = 'Computed Profit: BAD' ; length D_BAD_ $ 5; D_BAD_ = ' '; EP_BAD_ = .; BP_BAD_ = .; CP_BAD_ = .; *** Compute Expected Consequences and Choose Decision; _decnum = 1; drop _decnum; D_BAD_ = '1' ; EP_BAD_ = _P0 * 1 + _P1 * 0; *** Decision Matrix; array RGdema [2,1] _temporary_ ( /* row 1 */ 1 /* row 2 */ 0 ); *** Find Index of Target Category; drop _tarnum; select( F_BAD ); when('1' ) _tarnum = 1; when('0' ) _tarnum = 2; otherwise _tarnum = 0; end; if _tarnum <= 0 then goto RGdeex; *** Computed Consequence of Chosen Decision; CP_BAD_ = RGdema [_tarnum,_decnum]; *** Best Possible Consequence of Any Decision without Cost; array RGdebe [2] _temporary_ ( 1 0); BP_BAD_ = RGdebe [_tarnum]; RGdeex:; *** End Decision Processing ; *** Posterior Probabilities and Predicted Level; label P_BAD1 = 'Predicted: BAD=1' ; label P_BAD0 = 'Predicted: BAD=0' ; P_BAD1 = _P0; _MAXP = _P0; _IY = 1; P_BAD0 = _P1; if (_P1 - _MAXP > 1e-8) then do; _MAXP = _P1; _IY = 2; end; I_BAD = RGDRF[_IY]; U_BAD = RGDRU[_IY]; *************************************; ***** end scoring code for regression; *************************************;