BookmarkSubscribeRSS Feed
asifgeneral
Calcite | Level 5

Hello,

 

How to Replacing Variables by WoE (Weight of Evidence) in Logistic Regression in SAS.

 

Sas enterprise miner gives a conveient way to do this, but how to do it in sas 9.4? Can you please help.

 

Regards, 

 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

@asifgeneral wrote:

Hello,

 

How to Replacing Variables by WoE (Weight of Evidence) in Logistic Regression in SAS.

 

Sas enterprise miner gives a conveient way to do this, but how to do it in sas 9.4? Can you please help.

 

Regards, 

 


Is the question really about how to compute the WOE? Or is the question really how to replace the values of a variable, as it says?

--
Paige Miller
Ksharp
Super User

I would use PROC FORMAT . Something like:

 


data fmt_&var ;
 set cutpoints;
 start=lag(cutpoints);
 end=cutpoints;
 if start=.M then hlo='IL';
 if end=.I then hlo='IH';
 if _n_ ne 1 then do;group+1;output;end;
run;
data fmt_&var(index=(group));
 merge  fmt_&var woe_&var(keep=group woe);
 by group;
 retain fmtname "&var" type 'I';
 keep group fmtname type start end woe hlo;
 rename woe=label;
 label group=' ';
run;
proc format cntlin=fmt_&var library=z;
run;
options fmtsearch=(z);
data want;
 set have;
 woe_age=input(age,age.);
 woe_sex=input(sex,sex.);
 woe_client_s=input(client_s,client_s.);
 woe_version=input(version,version.);
 woe_interset=input(interset,interset.);
 woe_insure_y=input(insure_y,insure_y.);
 woe_gps=input(gps,gps.);
 woe_brand=input(brand,brand.);
 woe_up_brand=input(up_brand,up_brand.);
 woe_shop_p=input(shop_p,shop_p.);
 woe_brand_p=input(brand_p,brand_p.);
 woe_birth_p=input(birth_p,birth_p.);
 woe_rent=input(rent,rent.);
 woe_first_p=input(first_p,first_p.);
 woe_tax=input(tax,tax.);
 woe_capital=input(capital,capital.);
 woe_from_s=input(from_s,from_s.);
 woe_price_c=input(price_c,price_c.);
 woe_price_p=input(price_p,price_p.);
 *woe_ratio_f=input(ratio_f,ratio_f.);
 woe_insurea=input(insurea,insurea.);
 woe_insureb=input(insureb,insureb.);


 woe_cont_n=input(cont_n,cont_n.);
 woe_marry=input(marry,marry.);
 woe_pay_way=input(pay_way,pay_way.);
 woe_insure_w=input(insure_w,insure_w.);
 woe_bussines=input(bussines,bussines.);
 woe_culture=input(culture,culture.);
 woe_group_c=input(group_c,group_c.);
 woe_duty=input(duty,duty.);
 woe_car_usag=input(car_usag,car_usag.);
 woe_icompany=input(icompany,icompany.);
 woe_cont_a_n=input(cont_a_n,cont_a_n.);
 woe_nation=input(nation,nation.);

run;












/******Firstly,Check Multicollinearity***********/
%let varlist= 
woe_sex
woe_client_s
woe_interset
woe_insure_y
woe_gps
woe_brand
woe_shop_p
woe_rent
woe_first_p
woe_cont_n
woe_marry
woe_culture
woe_nation
;



%let n=%sysfunc(countw(&varlist,%str( )));
%put &n ;

proc logistic data=want outest=est(keep=intercept &varlist);
model good_bad(event='good')= &varlist 
/outroc=x.roc lackfit scale=none aggregate rsquare  firth corrb  /* selection=stepwise sle=0.1 sls=0.1*/ ;
output out=output h=h c=c cbar=cbar predicted=PredProb;
run;

 

 

But if you are sas rookie, you could write it by hand, something like :

 

data want;

 set have;

 if missing(age) then woe_age=0.213;

   else if age<20 then woe_age=0.342;

     else woe_age=0.4345;

 

 if missing(sex) then woe_sex=0.234;

  else if sex='F' then woe_sex=0.456;

   else if sex='M' then woe_sex=0.675;

run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1995 views
  • 0 likes
  • 3 in conversation