/ksͳ�����ļ������ͼ/
    libname loan “d:\2019xyt”;
    /ks����/
    %macro ksstat(dsin,probvar,dvvar,dsks,m_ks);

    proc sort data=&dsin;
    by &probvar;
    run;

    proc sql noprint;
    select sum(&dvvar) into:p from &dsin;
    select count(*) into:ntot from &dsin;
    quit;

    %let n=%eval(&ntot-&p);/total negative(good)/
    /**/

    data &dsks;
    set &dsin nobs=nn;
    by &probvar;
    retain tile 1 totp 0 totn 0;
    tile_size=ceil(nn/100);

    if &dvvar=1 then totp=totp+&dvvar;
    else totn=totn+1;

    pper=totp/&p;
    nper=totn/&n;

    if n=tile*tile_size then do;
    output;
    if tile<100 then do;
    tile=tile+1;
    sumresp=0;
    end;
    end;
    keep tile pper nper;
    run;

    data temp;
    tile=0;
    pper=0;
    nper=0;
    run;

    data &dsks;
    set temp &dsks;
    run;

    data &dsks;
    set &dsks;
    tile=tile/100;
    label pper=”percent of positives”;
    label nper=”percent of negaives”;
    label tile=”percent of population”;
    ks=nper-pper;
    run;

    proc sql noprint;
    select max(ks) into :&m_ks from &dsks;
    run;quit;

    proc datasets library=work nodetails nolist;
    delete temp;
    run;
    quit;

    %mend;

    /��ͼ/
    %macro plotks(dsks);

    symbol1 color=red interpol=join value=dot height=1;
    legend1 position=top;

    symbol2 color=blue interpol=join value=dot height=1;
    symbol3 color=green interpol=join value=dot height=1;
    proc gplot data=&dsks;
    plot(nper pper ks)*tile /overlay legend=legend1;
    run;
    quit;
    goptions reset=all;
    %mend;

    proc contents data=loan.practice_2_fa(drop=v_5) out=a noprint;run;
    proc sql noprint;
    select name into:var separated by ‘ ‘ from a;quit;

    %let varlist=&var.;

    proc logistic data=loan.practice_2_fa outest=model_parms;
    model v_5(event=’1’)=&var./selection=stepwise sls=0.05 sle=0.05;
    output out=pred_probs p=pred_v_5;
    run;

    /use the macro/

    %let dsin=pred_probs;
    %let probvar=pred_v_5;
    %let dvvar=v_5;
    %let dsks=dsks;
    %let ks=;
    %ksstat(&dsin,&probvar,&dvvar,&dsks,ks);

    %put >>>>>>>>>>>>>>>>>>>>>>>>>>> ks-stat=&ks <<<<<<<<<<<<<<<<<<<<<<<<<;

    %plotks(&dsks);