* ; * Memory Based Reasoning Training ; * ; * ; * Score training data ; * ; proc pmbr score=EMDATA.VIEW_GF2 out=work._tmpmbr data=EMDATA.VIEW_GF2 dmdbcat=EMPROJ.dm_DGM00000 k=16 method=RDTREE; target DIAB; var STNPREG STGLU STBP STBMI STAGE; data EMPROJ.OUT_OTUA; set work._tmpmbr; *--------------------------------------------------------------*; * Memory-Based Reasoning: DIAB: Decisions; *--------------------------------------------------------------*; *** Warning Variable; length _warn_ $4; label _warn_ = 'Warnings'; drop _decwarn; _decwarn = 0; *** Check Posterior Probabilities; if not (n( P_DIAB1 ) & ( P_DIAB1 <= 1) & (0 <= P_DIAB1 ) & n( P_DIAB0 ) & ( P_DIAB0 <= 1) & (0 <= P_DIAB0 ) ) then do; _decwarn = 1; substr(_warn_,3,1) = 'P'; P_DIAB1 = .; P_DIAB0 = .; goto _demi; end; *** Update Posterior Probabilities; P_DIAB1 = P_DIAB1 * 0.39 / 0.39; P_DIAB0 = P_DIAB0 * 0.61 / 0.61; drop _sum; _sum = P_DIAB1 + P_DIAB0 ; if _sum > 0 then do; P_DIAB1 = P_DIAB1 / _sum; P_DIAB0 = P_DIAB0 / _sum; end; *** Decision Processing; label D_DIAB_ = 'Decision: DIAB' ; label EP_DIAB_ = 'Expected Profit: DIAB' ; label BP_DIAB_ = 'Best Profit: DIAB' ; label CP_DIAB_ = 'Computed Profit: DIAB' ; length D_DIAB_ $ 5; *** Initialize to Missing if Target Used; _demi:; D_DIAB_ = ' '; EP_DIAB_ = .; BP_DIAB_ = .; CP_DIAB_ = .; if _decwarn then goto _deex; *** Compute Expected Consequences and Choose Decision; _decnum = 1; drop _decnum; D_DIAB_ = '1' ; EP_DIAB_ = P_DIAB1 * 1 + P_DIAB0 * 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( DIAB , 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_DIAB_ = _dema [_tarnum,_decnum]; *** Best Possible Consequence of Any Decision without Cost; array _debe [2] _temporary_ ( 1 0); BP_DIAB_ = _debe [_tarnum]; _deex:; *** End Decision Processing ; run; * ; * Score validation data ; * ; proc pmbr score=EMDATA.VIEW_QXS out=work._tmpmbr data=EMDATA.VIEW_GF2 dmdbcat=EMPROJ.dm_DGM00000 k=16 method=RDTREE; target DIAB; var STNPREG STGLU STBP STBMI STAGE; data EMPROJ.OUT_D5QJ; set work._tmpmbr; *--------------------------------------------------------------*; * Memory-Based Reasoning: DIAB: Decisions; *--------------------------------------------------------------*; *** Warning Variable; length _warn_ $4; label _warn_ = 'Warnings'; drop _decwarn; _decwarn = 0; *** Check Posterior Probabilities; if not (n( P_DIAB1 ) & ( P_DIAB1 <= 1) & (0 <= P_DIAB1 ) & n( P_DIAB0 ) & ( P_DIAB0 <= 1) & (0 <= P_DIAB0 ) ) then do; _decwarn = 1; substr(_warn_,3,1) = 'P'; P_DIAB1 = .; P_DIAB0 = .; goto _demi; end; *** Update Posterior Probabilities; P_DIAB1 = P_DIAB1 * 0.39 / 0.39; P_DIAB0 = P_DIAB0 * 0.61 / 0.61; drop _sum; _sum = P_DIAB1 + P_DIAB0 ; if _sum > 0 then do; P_DIAB1 = P_DIAB1 / _sum; P_DIAB0 = P_DIAB0 / _sum; end; *** Decision Processing; label D_DIAB_ = 'Decision: DIAB' ; label EP_DIAB_ = 'Expected Profit: DIAB' ; label BP_DIAB_ = 'Best Profit: DIAB' ; label CP_DIAB_ = 'Computed Profit: DIAB' ; length D_DIAB_ $ 5; *** Initialize to Missing if Target Used; _demi:; D_DIAB_ = ' '; EP_DIAB_ = .; BP_DIAB_ = .; CP_DIAB_ = .; if _decwarn then goto _deex; *** Compute Expected Consequences and Choose Decision; _decnum = 1; drop _decnum; D_DIAB_ = '1' ; EP_DIAB_ = P_DIAB1 * 1 + P_DIAB0 * 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( DIAB , 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_DIAB_ = _dema [_tarnum,_decnum]; *** Best Possible Consequence of Any Decision without Cost; array _debe [2] _temporary_ ( 1 0); BP_DIAB_ = _debe [_tarnum]; _deex:; *** End Decision Processing ; run; * ; * Score test data ; * ; proc pmbr score=EMDATA.VIEW_PXU out=work._tmpmbr data=EMDATA.VIEW_GF2 dmdbcat=EMPROJ.dm_DGM00000 k=16 method=RDTREE; target DIAB; var STNPREG STGLU STBP STBMI STAGE; data EMPROJ.OUT_II9L; set work._tmpmbr; *--------------------------------------------------------------*; * Memory-Based Reasoning: DIAB: Decisions; *--------------------------------------------------------------*; *** Warning Variable; length _warn_ $4; label _warn_ = 'Warnings'; drop _decwarn; _decwarn = 0; *** Check Posterior Probabilities; if not (n( P_DIAB1 ) & ( P_DIAB1 <= 1) & (0 <= P_DIAB1 ) & n( P_DIAB0 ) & ( P_DIAB0 <= 1) & (0 <= P_DIAB0 ) ) then do; _decwarn = 1; substr(_warn_,3,1) = 'P'; P_DIAB1 = .; P_DIAB0 = .; goto _demi; end; *** Update Posterior Probabilities; P_DIAB1 = P_DIAB1 * 0.39 / 0.39; P_DIAB0 = P_DIAB0 * 0.61 / 0.61; drop _sum; _sum = P_DIAB1 + P_DIAB0 ; if _sum > 0 then do; P_DIAB1 = P_DIAB1 / _sum; P_DIAB0 = P_DIAB0 / _sum; end; *** Decision Processing; label D_DIAB_ = 'Decision: DIAB' ; label EP_DIAB_ = 'Expected Profit: DIAB' ; label BP_DIAB_ = 'Best Profit: DIAB' ; label CP_DIAB_ = 'Computed Profit: DIAB' ; length D_DIAB_ $ 5; *** Initialize to Missing if Target Used; _demi:; D_DIAB_ = ' '; EP_DIAB_ = .; BP_DIAB_ = .; CP_DIAB_ = .; if _decwarn then goto _deex; *** Compute Expected Consequences and Choose Decision; _decnum = 1; drop _decnum; D_DIAB_ = '1' ; EP_DIAB_ = P_DIAB1 * 1 + P_DIAB0 * 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( DIAB , 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_DIAB_ = _dema [_tarnum,_decnum]; *** Best Possible Consequence of Any Decision without Cost; array _debe [2] _temporary_ ( 1 0); BP_DIAB_ = _debe [_tarnum]; _deex:; *** End Decision Processing ; run;