/���������������ַ���������Ӧ������Ԥ����/

    /*
    Credit Risk Scorecards: Development and Implementation using SAS
    (c) Mamdouh Refaat
    /

    //
    /
    Macro: InfValue
    /*
    /
    %macro InfValue(DSin, XVar, YVarBin, MIV); /��������Ϣֵ�����ݼ�MIV/

    / Extract the frequency table using proc freq,
    and the categories of the X variable
    /

    proc freq data=&DSin noprint; /��Ƶ�ʱ�/
    table &XVar*&YvarBin /out=Temp_freqs;
    table &XVar /out=Temp_Xcats;
    run;

    proc sql noprint;
    / Count the number of obs and categories of X /
    %local R C; / rows and columns of freq table /
    select count() into : R from temp_Xcats; /�õ��������� count��)�൱�ڶ��м��� �ж����оͶ���/
    select count(*) into : N from &DSin;
    quit;

    / extract the categories of X into CatX_i /
    data Null;
    set tempXCats;
    call symput(“CatX
    “||compress(N), &Xvar);
    run;

    proc sql noprint;
    / extract n_i_j/
    %local i j;
    %do i=1 %to &R;
    %do j=1 %to 2;/ we know that YVar is 1/0 - numeric /
    %local N&i.&j;
    Select Count into :N&i.&j from tempfreqs where &Xvar =”&&CatX&i” and &YVarBin = %eval(&j-1);
    %end;
    %end;
    quit;

    / calculate N_1,N_2 /
    %local N1s N_2s;
    %let N_1s=0;
    %let N_2s=0;
    %do i=1 %to &r;
    %let N_1s=%sysevalf(&N_1s + &&N
    &i.1);
    %let N_2s=%sysevalf(&N_2s + &&N
    &i._2);
    %end;

    / substitute in the equation for IV /
    %local IV;
    %let IV=0;
    %do i=1 %to &r;
    %let IV = %sysevalf(&IV + (&&N&i._1/&N_1s - &&N&i.2/&N_2s)%sysfunc(log(%sysevalf(&&N&i._1&N2s/(&&N&i._2*&N_1s)))) );
    %end;

    1. data char_iv;
    2. retain m_iv;
    3. var=_n_;
    4. m_iv=&iv;
    5. run;

    %let &M_IV=&IV;

    data information_value;
    var=”&xvar”;
    iv=&m_iv;
    run;

    proc sql;
    title “�ַ�������v5����Ϣֵ”;
    create table iv
    &xvar as
    select * from information_value;
    quit;

    %put &M_IV;

    / clean the workspace /
    proc datasets library=work NOPRINT;
    delete temp_freqs temp_Xcats;
    quit;
    %mend;

    proc contents data=loan.clust_out out=i_v noprint;run;
    proc sql noprint;
    select name,count(*) into :charlist separated by ‘ ‘ ,:n from i_v
    where type=2;
    quit;
    proc sql noprint;
    create table char_list as
    select name from i_v
    where type=2;
    quit;

    %put &charlist.; /32���ַ������Ѿ�׼������ ������33����ȥ��id/
    %put &n.;

    %macro caliv();
    %let dsid=%sysfunc(open(char_list));
    %if &dsid gt 0 %then %do;
    %let nobs=%sysfunc(attrn(&dsid,nobs));
    %do i=1 %to &nobs;
    %let rc=%sysfunc(fetchobs(&dsid,&i));
    %let varnume=%sysfunc(varnum(&dsid,name));
    %let variable=%sysfunc(getvarc(&dsid,&varnume)); /
    ��������variable�ij��� _/
    %let Dsin=loan.clust_out;
    %let Xvar=&variable;
    %let YVarBin=V_5;
    %let M_IV=;
    %InfValue(&Dsin, &Xvar, &YVarBin,M_IV);

    1. %end;
    2. %let dsid=%sysfunc(close(&dsid));
    3. %end;

    %mend cal_iv;

    %cal_iv;

    proc contents data=work.all out=all noprint;
    quit;

    proc sql noprint;
    create table char_name as
    select memname,name from work.all
    where name=”iv” ;
    quit;
    proc sql noprint;
    select memname into:ccharlist separated by ‘ ‘ from char_name;
    quit;

    data ivtotal;
    set &ccharlist;
    run;

    /ɾ���ظ��۲�/
    proc sort data=ivtotal out=loan.iv_total nodup;
    by var;
    run;

    proc sort data=loan.ivtotal;
    by iv ;
    run;
    proc print data=loan.iv_total;run;
    /_M_IV������־����� �õ������������������M_IV
    /

    /iv��Ϣֵ iv����0.3˵��Ԥ����ǿ iv��0.1��0.3˵��Ԥ�����е� �������0.1��ֻ��v_31 v_172/