libname loan “d:2019xyt”;
    /�������״�ɸѡ/
    option mprint mlogic;
    /�õ����б��������ԣ�����type=1��ʾ��ֵ�����ݣ�type=2��ʾ�ַ�������/
    proc contents data=loan.practice_1(drop= v_5)
    noprint out=origin_dev_variable;
    run;

    /ȡ��������ֵ�ͱ�������/
    data origin_num_var;
    set origin_dev_variable;
    where type=1;
    keep name;
    run;

    /sysfunc��һ��ͨ�亯����������Ϊ������data���е�exist����/
    %macro var_chi();
    %if %sysfunc(exist(loan.origin_var_chisq_list)) ne 0 %then %do;
    proc datasets lib=loan nolist;
    delete origin_var_chisq_list;
    quit;

    data loan.originvar_chisq_list;/����������� �Ϳ���Pֵ�Ϳ����÷ֵ�/
    length var$80 scorechisq 5 probchisq 8;
    stop;
    run;
    %end;
    %let dsid=%sysfunc(open(origin_num_var));
    %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��� _/
    ods listing close;
    ods results off;
    ods output
    effectnotinmodel=var_chisq(keep=effect scorechisq probchisq rename=(effect=var));

    /��ÿһ���������������߼��ع� �������е�ѭ��/
    proc logistic data=loan.practice1 desc;
    /_weight weight; ������û��Ȩ��weight��һ����
    /
    model v_5=&variable./selection=s sls=0.3 maxstep=1 details;
    run;
    ods output close;
    ods results on;
    ods listing;

    data var_chisq;
    length var $ 80;
    set var_chisq;
    run;
    proc append base=loan.origin_var_chisq_list data=var_chisq force;
    run;

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

    %mend var_chi;
    %var_chi;

    /ɸѡ������Pֵ����0С��0.01��/
    data loan.bk1num_var;/������ֵ�ͱ����б�/
    set loan.origin_var_chisq_list;
    where probchisq le 0.01 and probchisq ge 0; /
    һ��ȡPֵΪ0.3 ������ʵ��Ӧ��ֻ��le ��Ҫ����ge 0 ��ΪȱʧֵΪ������_/
    run;

    proc sql noprint;
    select var,count(*)into:m1_num_var_bk1 separated by ‘ ‘,:m1_num_var_bk1_cnt
    from loan.bk1_num_var
    ;
    quit;

    %put &m1_num_var_bk1.;
    %put &m1_num_var_bk1_cnt.;

    data loan.practice_2;
    set loan.practice_1(keep=
    v_5
    &m1_num_var_bk1.
    );
    run;

    proc contents data=loan.practice_2 (drop=v_5) out=a noprint;run;

    proc sql noprint;
    select name into:dev separated by ‘ ‘ from a
    where type=1;
    quit;

    %put &dev.;

    proc logistic data=loan.practice2 out=c1; /�߼��ع�/
    model v_5(event=’1’)=&dev /
    ��badgood=1�Ľ����߼��ع�ģ��/
    /selection=stepwise /ȫģ�� ���в����� ������̫����/
    CLPARM=WALD
    RSQUARE /R^2Խ��Խ�� /
    lackfit
    stb
    outroc=roc1 /����ROC����/
    ;
    output out=pred p=phat /���Ԥ�����ݼ�pred/
    ;
    score out=c2
    ;
    run;

    /*����practice_2����

    libname loan “d:\2019xyt”;

    proc contents data=loan.Practice_2 out=a noprint;run;
    data a;set a;if name=”v_5” then delete;run;
    proc sql noprint;select name into:varlist separated by ‘ ‘ from a;quit;

    %put &varlist.;

    proc factor data=loan.Practice_2 n=40 out=loanfactor outstat=aaaa;
    var &varlist.;
    run;
    /
    /

    proc princomp data=loan.Practice_1 n=68 out=loanfactor outstat=aaaa;
    var &varlist.;
    run;
    */

    /
    data loan.factor;
    set loanfactor(keep=v_5 Factor1-Factor40);
    run;
    /

    /
    proc logistic data=loan.factor out=c1;
    model v_5(event=’1’)=factor1-factor40
    /selection=stepwise
    RSQUARE
    lackfit
    outroc=roc1;
    output out=pred p=phat
    ;
    score out=c2;
    run;
    /
    /����һ�����ӷ���/

    /��������������������
    ��Ҫ�����������ӷ�����ά ���ܽ��ͱ������ƣ�����������������������
    /
    libname loan “d:2019xyt”;
    /�������״�ɸѡ/
    option mprint mlogic;
    /�õ����б��������ԣ�����type=1��ʾ��ֵ�����ݣ�type=2��ʾ�ַ�������/
    proc contents data=loan.test_1(drop= v_5)
    noprint out=origin_dev_variable;
    run;

    /ȡ��������ֵ�ͱ�������/
    data origin_num_var;
    set origin_dev_variable;
    where type=1;
    keep name;
    run;

    /sysfunc��һ��ͨ�亯����������Ϊ������data���е�exist����/
    %macro var_chi();
    %if %sysfunc(exist(loan.origin_var_chisq_list)) ne 0 %then %do;
    proc datasets lib=loan nolist;
    delete origin_var_chisq_list;
    quit;

    data loan.originvar_chisq_list;/����������� �Ϳ���Pֵ�Ϳ����÷ֵ�/
    length var$80 scorechisq 5 probchisq 8;
    stop;
    run;
    %end;
    %let dsid=%sysfunc(open(origin_num_var));
    %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��� _/
    ods listing close;
    ods results off;
    ods output
    effectnotinmodel=var_chisq(keep=effect scorechisq probchisq rename=(effect=var));

    /��ÿһ���������������߼��ع� �������е�ѭ��/
    proc logistic data=loan.test1 desc;
    /_weight weight; ������û��Ȩ��weight��һ����
    /
    model v_5=&variable./selection=s sls=0.3 maxstep=1 details;
    run;
    ods output close;
    ods results on;
    ods listing;

    data var_chisq;
    length var $ 80;
    set var_chisq;
    run;
    proc append base=loan.origin_var_chisq_list data=var_chisq force;
    run;

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

    %mend var_chi;
    %var_chi;

    /ɸѡ������Pֵ����0С��0.01��/
    data loan.bk1num_var;/������ֵ�ͱ����б�/
    set loan.origin_var_chisq_list;
    where probchisq le 0.01 and probchisq ge 0; /
    һ��ȡPֵΪ0.3 ������ʵ��Ӧ��ֻ��le ��Ҫ����ge 0 ��ΪȱʧֵΪ������_/
    run;

    proc sql noprint;
    select var,count(*)into:m1_num_var_bk1 separated by ‘ ‘,:m1_num_var_bk1_cnt
    from loan.bk1_num_var
    ;
    quit;

    %put &m1_num_var_bk1.;
    %put &m1_num_var_bk1_cnt.;

    data loan.test_2;
    set loan.test_1(keep=
    v_5
    &m1_num_var_bk1.
    );
    run;

    proc contents data=loan.test_2 (drop=v_5) out=a noprint;run;

    proc sql noprint;
    select name into:dev separated by ‘ ‘ from a
    where type=1;
    quit;

    %put &dev.;

    proc logistic data=loan.test2 out=c1; /�߼��ع�/
    model v_5(event=’1’)=&dev /
    ��badgood=1�Ľ����߼��ع�ģ��/
    /selection=stepwise /ȫģ�� ���в����� ������̫����/
    CLPARM=WALD
    RSQUARE /R^2Խ��Խ�� /
    lackfit
    stb
    outroc=roc1 /����ROC����/
    ;
    output out=pred p=phat /���Ԥ�����ݼ�pred/
    ;
    score out=c2
    ;
    run;