OK. I made a sample data for running my code.
data score_card;
call streaminit(123);
do i=1 to 10000;
*total_score=rand('integer',400,600);
total_score=int(rand('uniform')*200) + 400;
output;
end;
drop i;
run;
proc sql noprint;
select min(total_score) ,max(total_score) into :score_min, :score_max from score_card;
quit;
/****** Get cutpoint ******/
proc delete data=cutpoint;run;
%macro cutpoint;
%do score=&score_min %to &score_max;
data test_total_score;
set score_card;
_status=ifc(total_score ge &score,'good','bad ');
run;
proc npar1way data=test_total_score edf noprint;
class _status;
var total_score;
output out=cutpoint_ks(keep=_KS_) edf;
run;
data temp_cutpoint;
retain cutpoint &score ;
set cutpoint_ks ;
label cutpoint='分割点' _ks_='KS值';
run;
proc append base=cutpoint data=temp_cutpoint force;run;
%end;
%mend;
%cutpoint
proc sql noprint;
select cutpoint into : cutpoint
from cutpoint
having _KS_=max(_KS_);
quit;
data final_total_score;
set score_card;
call streaminit(123);
good_bad=ifc(rand('bern',0.2),'bad','good');
run;
proc sgpanel data=final_total_score;
panelby good_bad/layout=rowlattice onepanel noborder novarname;
histogram total_score;
refline &cutpoint /axis=x;
run;
Wow.
Who can top THAT?!
Well, without further ado, I declare @Ksharp The Solution.
Not necessarily for the problem at hand. But just in general.
Thanks so much to all of you that contributed.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.