楼主: neoliberals
897 1

[SAS EM] sas宏筛选重复ID《信用风险评分卡研究》 [推广有奖]

  • 0关注
  • 0粉丝

初中生

47%

还不是VIP/贵宾

-

威望
0
论坛币
1 个
通用积分
1.0000
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
215 点
帖子
8
精华
0
在线时间
20 小时
注册时间
2019-4-4
最后登录
2020-4-2

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
/* macro extunique */
%macro extunique(Dsin,idvar,dsout,dspup);
/* extract the id's only to speed calculations*/
data temp_allids;
set &dsin;
keep &idvar;
run;
/*extract the id's with count>1*/
data temp_nid;
set temp_uid;
if _count>1 then output;
keep &idvar;
run;
/*sort the data using idvar and output only one row per
idvar value*/
proc sort data=&sin;
by &idvar;
run;
data &dsout;
set &dsin;
by &idvar;
if fitst.&idvar;
run;

/*extract the full records for the repeates id's*/
proc sql noprint;
create table &dsdup as select b.*from temp_nid a,&dsin b
where a.&idvar=b.&idvar;
run;
quit;
/*clean the workspace*/
proc datasets nodetails nolist;
delete temp_allids temp_uid temp_nid;
run;
quit;
%mend;

data mv;
input id balance @@;
datalines;
01 1223 01 2322 02 344 02 21221  
03 2334 04 222 05 222 06 222
;
run;

%let idvar=id;
%let dsin=mv;
%let dsout=mv_id;
%let dsdup=duplicate_id;
%extunique(&dsin,&idvar,&dsout,&dsdup);

set temp_uid; 书中后面给了个宏,但是这个表是从哪来的???执行也是错误
ERROR: 文件“WORK.TEMP_UID.DATA”不存在。



二维码

扫码加我 拉你入群

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

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

关键词:信用风险 SAS宏 评分卡 Calculations Calculation

沙发
neoliberals 发表于 2019-6-25 14:34:25 |只看作者 |坛友微信交流群
/* macro extunique */
%macro extunique(Dsin,idvar,dsout,dspup);
/* extract the id's only to speed calculations*/
data temp_allids;
set &dsin;
keep &idvar;
run;
/*extract the unique id's and their conts*/
proc sql noprint;
create table temp_uid as select &idvar,count(&idvar) as _count
from temp_allids group by &idvar;
run;quit;
/*extract the id's with count>1*/
data temp_nid;
set temp_uid;
if _count>1 then output;
keep &idvar;
run;
/*sort the data using idvar and output only one row per
idvar value*/
proc sort data=&dsin;
by &idvar;
run;
data &dsout;
set &dsin;
by &idvar;
if first.&idvar;
run;

/*extract the full records for the repeates id's*/
proc sql noprint;
create table &dsdup as select b.*from temp_nid a,&dsin b
where a.&idvar=b.&idvar;
run;
quit;
/*clean the workspace*/
proc datasets nodetails nolist;
delete temp_allids temp_uid temp_nid;
run;
quit;
%mend;

data mv;
input id balance @@;
datalines;
01 1223 01 2322 02 344 02 21221  
03 2334 04 222 05 222 06 222
;
run;

%let idvar=id;
%let dsin=mv;
%let dsout=mv_id;
%let dsdup=duplicate_id;
%extunique(&dsin,&idvar,&dsout,&dsdup);


宏里面少了一段  还有几个代码写错了

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-26 01:13