楼主: yukai08008
2167 0

[学习分享] WOE_SAS宏代码_Andy的加工贴1 [推广有奖]

  • 2关注
  • 17粉丝

已卖:19份资源

讲师

2%

还不是VIP/贵宾

-

威望
0
论坛币
2176 个
通用积分
3.0600
学术水平
10 点
热心指数
7 点
信用等级
7 点
经验
5915 点
帖子
120
精华
0
在线时间
556 小时
注册时间
2012-11-28
最后登录
2022-4-11

楼主
yukai08008 在职认证  发表于 2016-8-5 14:39:24 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

以下宏就是计算WOE的方法,关于其应用和介绍可以看:
1、http://blog.sina.com.cn/s/blog_8813a3ae0102uyo3.html
2、http://blog.csdn.net/kevin7658/article/details/50780391
本质上,IV,WOE,熵,以及logit(odds)的概念都是互通的。

/*取自《信用风险评分卡研究_基于SAS的开发与实施》*/
%macro calcwoe(dsin,ivvar,dvvar,woeds,woevar,dsout,daccess);
/*输出频数*/
proc freq data=&dsin noprint;
tables &ivvar * &dvvar/out=temp_freqs;
run;
/*排序*/
proc sort data=temp_freqs;
by &ivvar * &dvvar;
run;
/*根据变量的每一个水平对目标汇总,c1t,c0t是累计值*/
data temp_woe1;
set temp_freqs;
retain c1 c0 c1t 0 c0t 0;
by &ivvar &dvvar;
if first.&ivvar then do;
c0=count;
c0t=c0t+c0;
end;
if last.&ivvar then do;
c1=count;
c1t=c1t+c1;
end;
if last.&ivvar then output;
drop count percent &dvvar;
call symput('c0t',c0t);
call symput('c1t',c1t);
run;
/*如果good和bad频数不为0则计算woe*/
data &woeds;
set temp_woe1;
goodist=c0/&c0t;
badist=c1/&c1t;
if(goodist > 0 and badist > 0) then woe=log(badist/goodist);
else woe=.;
keep &ivvar woe;
run;

proc sql noprint;
create table &dsout as
select a.*,b.woe as &woevar from &dsin a,&woeds b
where a.&ivvar=b.&ivvar;
quit;
proc sql noprint;
create table &daccess as
select a.*,b.woe as &woevar from &daccess a,&woeds b where
a.&ivvar=b.&ivvar;
quit;
/*清除工作空间*/
proc delete data=temp_freqs temp_woe1;
run;
quit;
%mend;

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Andy SAS宏 woe proc sql Details tables 开发

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-6 09:12