SAS中文论坛

标题: [转] SAS中Nodupkey和Nodup的区别 [打印本页]

作者: shiyiming    时间: 2013-8-8 07:30
标题: [转] SAS中Nodupkey和Nodup的区别
主要功能介绍:利用PROC SORT 过程中的Nodupkey和Nodup,进行删除数据集中重复的记录

1. nodupkey会把同by variable里变量有相同值的observation都删掉。这些observation包括那些与by variable里变量有相同值,但与剩下变量有不同值的observation。如,
input id1 $ id2 $ extra ;
cards;
aa ab 3
aa ab 3
aa ab 2
aa ab 1
;
proc sort nodupkey data=test3;
by id1 id2;
run;
options nocenter;
proc print data=test3;
run;
Obs    id1    id2    extra
1     aa     ab       3

2. nodup会把那些仅与by variable里变量有相同值的observation删掉,如
data test2;
input id1 $ id2 $ extra ;
cards;
aa ab 3
aa ab 3
aa ab 2
aa ab 1
;
proc sort nodup data=test2;
by id1 id2;
run;
options nocenter;
proc print data=test2;
run;
Obs    id1    id2    extra
1     aa     ab       3
2     aa     ab       2
3     aa     ab       1
但要注意的是nodup只会把相邻的且仅具有相同by variable变量值的observation删掉,如
data test1;
input id1 $ id2 $ extra ;
cards;
aa ab 3
aa ab 1
aa ab 2
aa ab 3
;
proc sort nodup data=test1;
by id1 id2;
run;
options nocenter;
proc print data=test1;
run;
Obs    id1    id2    extra
1     aa     ab       3
2     aa     ab       1
3     aa     ab       2
4     aa     ab       3

原帖:http://www.itongji.cn/article/101512422012.html
作者: shiyiming    时间: 2013-8-8 14:22
标题: Re: [转] SAS中Nodupkey和Nodup的区别
友情提示:建议在讲这两个选项的时候,把系统选项sortdup=physical|logical捏合在一起讲,这样会更加系统。
作者: shiyiming    时间: 2013-8-9 10:24
标题: Re: [转] SAS中Nodupkey和Nodup的区别
赞!
作者: shiyiming    时间: 2013-8-10 10:55
标题: Re: [转] SAS中Nodupkey和Nodup的区别
学习了




欢迎光临 SAS中文论坛 (http://www.mysas.net/forum/) Powered by Discuz! X3.2