## SAS Macro Aligning The Logit Variable to A Scorecard with Specific PDO and Base Point

%macro align_score(data = , y = , logit = , pdo = , base_point = , base_odds = , min_point = 100, max_point = 900); ***********************************************************; * THE MACRO IS TO ALIGN A LOGIT VARIABLE TO A SCORE WITH *; * SPECIFIC PDO, BASE POINT, AND BASE ODDS *; * ======================================================= *; * PAMAMETERS: *; * DATA : INPUT SAS DATA TABLE *; * Y : PERFORMANCE VARIABLE WITH 0/1 VALUE *; * LOGIT : A LOGIT VARIABLE TO BE ALIGNED FROM *; * PDO : PDO OF THE SCORE ALIGNED TO *; * BASE_POINT: BASE POINT OF THE SCORE ALIGNED TO *; * BASE_ODDS : ODDS AT BASE POINT OF THE SCORE ALIGNED TO *; * MIN_POINT : LOWER END OF SCORE POINT, 100 BY DEFAULT *; * MAX_POINT : UPPER END OF SCORE POINT, 900 BY DEFAULT *; * ======================================================= *; * OUTPUTS: *; * ALIGN_FORMULA.SAS *; * A SAS CODE WITH THE FORMULA TO ALIGN THE LOGIT FIELD *; * TO A SPECIFIC SCORE TOGETHER WITH THE STATISTICAL *; * SUMMARY OF ALIGN_SCORE *; ***********************************************************; options nocenter nonumber nodate mprint mlogic symbolgen orientation = landscape ls = 150 formchar = "|----|+|---+=|-/\<>*"; %local b0 b1; data _tmp1 (keep = &y &logit); set &data; where &y in (0, 1) and &logit ~= .; run; ods listing close; ods output ParameterEstimates = _est1 (keep = variable estimate); proc logistic data = _last_ desc; model &y = &logit; run; ods listing; data _null_; set _last_; if _n_ = 1 then do; b = - (estimate + (log(&base_odds) - (log(2) / &pdo) * &base_point)) / (log(2) / &pdo); call symput('b0', put(b, 15.8)); end; else do; b = estimate / (log(2) / &pdo); call symput('b1', put(b, 15.8)); end; run; filename formula "ALIGN_FORMULA.SAS"; data _null_; file formula; put @3 3 * "*" " SCORE ALIGNMENT FORMULA OF %upcase(&logit) " 3 * "*" ";"; put; put @3 "ALIGN_SCORE = MAX(MIN(ROUND((%trim(&b0)) - (%trim(&b1)) * %upcase(&logit), 1), &max_point), &min_point);"; put; run; data _tmp2; set _tmp1; %inc formula; run; proc summary data = _last_ nway; class &y; output out = _tmp3(drop = _type_ _freq_) min(align_score) = min_scr max(align_score) = max_scr median(align_score) = mdn_scr; run; data _null_; set _last_; file formula mod; if _n_ = 1 then do; put @3 3 * "*" " STATISTICAL SUMMARY OF ALIGN_SCORE BY INPUT DATA: " 3 * "*" ";"; end; put @3 "* WHEN %upcase(&y) = " &y ": MIN(SCORE) = " min_scr " MEDIAN(SCORE) = " mdn_scr " MAX(SCORE) = " max_scr "*;"; run; proc datasets library = work nolist; delete _: (mt = data); run; quit; ***********************************************************; * END OF THE MACRO *; ***********************************************************; %mend align_score;

Advertisements