/���ڰѾ���smote�㷨�������Ľ����clust_out�е�v_5=0�ĺϲ�/

    /��������smote�Ƕ�v_5=1�Ľ��� ����/

    data loan.newcases(drop=_NAME);
    set loan.new_cases;
    run;

    data loan.Change_clustchar_0;
    set loan.Change_clustchar;
    where v_5=0;
    run;

    /�����������/

    /Ϊ�˴�һ���������ݼ��г�ȡ�������ཻ������/
    %macro r2partitions(dsin,idvar,ds1,ds2,n1,n2,m_error);

    proc sql noprint;
    select count(*) into:N from &dsin;
    run;quit;

    /�����ȡ����������ԭʼ�� �д������/
    %let nx=%eval(&n1+&n2);
    %if &nx>&n %then %do;
    %let &m_error=error not enough recoreds in input dataset sampling canceled;
    %goto exit;
    %end;

    %let &m_error=ok;
    proc surveyselect noprint
    data=&dsin method=srs n=&n1 out=temp_1;
    run;

    data temp_1;
    set temp_1;
    selected=1;
    keep &idvar selected;
    run;

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

    proc sort data=temp_1;
    by &idvar;
    run;

    data temp;
    merge &dsin temp_1;
    by &idvar;
    keep &idvar selected;
    run;

    proc surveyselect noprint data=temp method=srs n=&n2 out=temp_2;
    where selected ne 1 ;
    run;

    data temp_1;
    set temp_1;
    keep &idvar;
    run;

    data temp_2;
    set temp_2;
    keep &idvar;
    run;

    proc sort data=&dsin;by &idvar;run;
    proc sort data=temp_1;by &idvar;run;
    proc sort data=temp_2;by &idvar;run;
    data &ds1;
    merge temp_1(in=x) &dsin;
    by &idvar;
    if x;
    run;
    data &ds2;
    merge temp_2(in=x) &dsin;
    if x;
    run;

    /
    proc datasets library=work nodetails;
    delete temp temp_1 temp_2;
    quit;
    /

    %exit:;
    %mend;

    data loan.Changeclustchar_0;
    set loan.Change_clustchar_0;
    id=_n
    ;
    run;

    %let dsin=loan.Change_clustchar_0;
    %let idvar=id;
    %let ds1=a0_m;
    %let ds2=a0_v;
    %let N1=10000;
    %let N2=5000;
    %let error=;
    %r2partitions(&dsin,&idvar,&ds1,&ds2,&n1,&n2,error);

    data loan.Newcases;
    set loan.New_cases;
    id=_n
    ;
    run;

    %let dsin=loan.New_cases;
    %let idvar=id;
    %let ds1=a1_m;
    %let ds2=a1_v;
    %let N1=10000;
    %let N2=100;
    %let error=;
    %r2partitions(&dsin,&idvar,&ds1,&ds2,&n1,&n2,error);

    data loan.mergev; /�ϲ������ݼ�_/
    set a0_m a1_m;
    drop id;
    run;

    proc freq data=loan.merge_v;
    table v_5;
    run;

    data loan.mergev;
    set loan.merge_v;
    id=_n
    ;
    run;

    proc sort data=loan.merge_v out=outsort;
    by v_5 id ;
    run;
    proc surveyselect data=outsort noprint
    method=srs rate=0.7 out=loan.practice;
    strata v_5 ;
    run;

    proc sql; /���ܱ���ɸ���������������practice�����������ݼ�/
    create table loan.test as
    select *
    from loan.merge_v
    where id not in(select id from loan.practice);
    quit;

    /�õ���������ѵ��ģ�͵����ݼ���loan.practice ��֤ģ�͵����ݼ���loan.test/
    /�õ���������ѵ��ģ�͵����ݼ���loan.practice ��֤ģ�͵����ݼ���loan.test/
    /�õ���������ѵ��ģ�͵����ݼ���loan.practice ��֤ģ�͵����ݼ���loan.test/
    /�õ���������ѵ��ģ�͵����ݼ���loan.practice ��֤ģ�͵����ݼ���loan.test/
    /�õ���������ѵ��ģ�͵����ݼ���loan.practice ��֤ģ�͵����ݼ���loan.test/

    libname loan “d:\2019xyt”;
    proc freq data=loan.practice;table v_5;run;
    proc freq data=loan.test;table v_5;run;