/*Information Value*/
%Macro IV_Numeric(Indep_Var);
proc rank data = test out = Ranks_Var ties = mean groups = 24;
var &Indep_Var.;
ranks X_rank_&Indep_Var.;
run;
%IV_Char(Ranks_Var,X_rank_&Indep_Var.);
%Mend IV_Numeric;
%Macro IV_Char(Data_Set,Cat_Var);
proc freq data =&Data_Set.(where=(y=1)) noprint;
table &Cat_Var.*y/out=freq_out_y1 (rename=(percent=percent1 count=count1)) ;
run;
proc freq data =&Data_Set.(where=(y=0)) noprint;
table &Cat_Var.*y/out=freq_out_y0 (rename=(percent=percent0 count=count0));
run;
data Freq_Out(drop=y &Cat_Var.);
merge freq_out_y0 freq_out_y1;
by &Cat_Var.;
woe=log(percent0/percent1);
iv=(percent0-percent1)*woe;
run;
proc means data= Freq_Out SUM; run;
data Freq_Out;
length Variable_Name $32.;
set Freq_Out;
Variable_Name="&Cat_Var.";
run;
proc append base = Final data = Freq_Out force;run;
%Mend IV_Char;
%Macro All_Independent_Vars();
/* Numeric Variables */
proc sql noprint;
select count(*) into :nobs from data_chars (where=( name <> "y" and type=1));
quit;run;
data _null_;
set data_chars (where=( name <> "y" and type=1));
call symput(compress("Var"
_n_),name);
run;
%do i=1 %to &nobs.;
%IV_Numeric(&&Var&i..);
%end;
/* Char Variables */
proc sql noprint;
select count(*) into :nobs from data_chars (where=( name <> "y" and type=2));
quit;run;
data _null_;
set data_chars (where=( name <> "y" and type=2));
call symput(compress("Var"
_n_),name);
run;
%do i=1 %to &nobs.;
%IV_Char(test,&&Var&i..);
%end;
proc means data=final SUM;
class Variable_Name;
var iv;output out=final_iv(drop=_type_) sum= ;
run;
%Mend All_Independent_Vars;
proc contents data=test out=data_chars(keep=name type) noprint;
run;
%All_Independent_Vars;
%Macro IV_Numeric(Indep_Var);
proc rank data = test out = Ranks_Var ties = mean groups = 24;
var &Indep_Var.;
ranks X_rank_&Indep_Var.;
run;
%IV_Char(Ranks_Var,X_rank_&Indep_Var.);
%Mend IV_Numeric;
%Macro IV_Char(Data_Set,Cat_Var);
proc freq data =&Data_Set.(where=(y=1)) noprint;
table &Cat_Var.*y/out=freq_out_y1 (rename=(percent=percent1 count=count1)) ;
run;
proc freq data =&Data_Set.(where=(y=0)) noprint;
table &Cat_Var.*y/out=freq_out_y0 (rename=(percent=percent0 count=count0));
run;
data Freq_Out(drop=y &Cat_Var.);
merge freq_out_y0 freq_out_y1;
by &Cat_Var.;
woe=log(percent0/percent1);
iv=(percent0-percent1)*woe;
run;
proc means data= Freq_Out SUM; run;
data Freq_Out;
length Variable_Name $32.;
set Freq_Out;
Variable_Name="&Cat_Var.";
run;
proc append base = Final data = Freq_Out force;run;
%Mend IV_Char;
%Macro All_Independent_Vars();
/* Numeric Variables */
proc sql noprint;
select count(*) into :nobs from data_chars (where=( name <> "y" and type=1));
quit;run;
data _null_;
set data_chars (where=( name <> "y" and type=1));
call symput(compress("Var"
_n_),name);
run;
%do i=1 %to &nobs.;
%IV_Numeric(&&Var&i..);
%end;
/* Char Variables */
proc sql noprint;
select count(*) into :nobs from data_chars (where=( name <> "y" and type=2));
quit;run;
data _null_;
set data_chars (where=( name <> "y" and type=2));
call symput(compress("Var"
_n_),name);
run;
%do i=1 %to &nobs.;
%IV_Char(test,&&Var&i..);
%end;
proc means data=final SUM;
class Variable_Name;
var iv;output out=final_iv(drop=_type_) sum= ;
run;
%Mend All_Independent_Vars;
proc contents data=test out=data_chars(keep=name type) noprint;
run;
%All_Independent_Vars;
No comments:
Post a Comment