label P_BAD1="Predicted: BAD=1"; P_BAD1 = P_BAD1; label P_BAD0="Predicted: BAD=0"; P_BAD0 = P_BAD0; label F_BAD="From:BAD"; F_BAD = substr(left(put(BAD,BEST12.)),1, min(16,length(left(put(BAD,BEST12.))))); F_BAD = upcase(F_BAD); label I_BAD="Into:BAD"; if max( P_BAD1, P_BAD0)=P_BAD1 then I_BAD = "1"; else if max( P_BAD1, P_BAD0)=P_BAD0 then I_BAD = "0"; *** Warning Variable; length _warn_ $4; label _warn_ = 'Warnings'; drop _decwarn; _decwarn = 0; *** Check Posterior Probabilities; if not (n( p_bad1 ) & ( p_bad1 <= 1) & (0 <= p_bad1 ) & n( p_bad0 ) & ( p_bad0 <= 1) & (0 <= p_bad0 ) ) then do; _decwarn = 1; substr(_warn_,3,1) = 'P'; p_bad1 = .; p_bad0 = .; goto _demi; end; *** Update Posterior Probabilities; drop _sum; _sum = p_bad1 + p_bad0 ; if _sum > 0 then do; p_bad1 = p_bad1 / _sum; p_bad0 = p_bad0 / _sum; end; *** 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; *** Initialize to Missing if Target Used; _demi:; D_BAD_ = ' '; EP_BAD_ = .; BP_BAD_ = .; CP_BAD_ = .; if _decwarn then goto _deex; *** Compute Expected Consequences and Choose Decision; _decnum = 1; drop _decnum; D_BAD_ = '1' ; EP_BAD_ = p_bad1 * 1 + p_bad0 * 0; *** Decision Matrix; array _dema [2,1] _temporary_ ( /* row 1 */ 1 /* row 2 */ 0 ); *** Normalize Target Value; length _targnor $ %DMNORLEN; drop _targnor; length _format $200; drop _format; _format = put( BAD , BEST12. ); %DMNORMCP(_format,_targnor); *** Find Index of Target Category; drop _tarnum; select( _targnor ); when('1' ) _tarnum = 1; when('0' ) _tarnum = 2; otherwise _tarnum = 0; end; if _tarnum <= 0 then goto _deex; *** Computed Consequence of Chosen Decision; CP_BAD_ = _dema [_tarnum,_decnum]; *** Best Possible Consequence of Any Decision without Cost; array _debe [2] _temporary_ ( 1 0); BP_BAD_ = _debe [_tarnum]; _deex:; *** End Decision Processing ;