SAS中文论坛

标题: 关于选取子集(数据集)的一个问题 [打印本页]

作者: shiyiming    时间: 2004-10-11 13:59
标题: 关于选取子集(数据集)的一个问题
data one;
input a b c d;
cards;
1 34 34 2
2  33 33 4
2 33 44 5
3 43 44 3
4 23 23 2
5 34 33 1
5 33 23 2
6 22 33 4
4 34 45 3
;
run;
现在考虑数据one中变a,如果a取某个值的频次大于1(如a=2的记录有第2条和第3条),此时根据变量d的优先顺序来决定改保留那条记录,d的优先顺序为:2 5 1 4 3 ,比方说a=2的记录有第2条和第3条,根据变量d的优先顺序,我们就保留第3条记录,将第2条记录删除。这样就可以得到原数据的一个子集。
请问如何用程序来实现?
作者: shiyiming    时间: 2004-10-11 15:29
标题: 试试看
data one;
input a b c d;
cards;
1 34 34 2
2 33 33 4
2 33 44 5
3 43 44 3
4 23 23 2
5 34 33 1
5 33 23 2
6 22 33 4
4 34 45 3
;
run;
data one_1;
set one;
if d=2 then turn=1;
if d=5 then turn=2;
if d=1 then turn=3;
if d=4 then turn=4;
if d=3 then turn=5;
run;
proc sort data=one_1;
by a turn;
run;
data one_2;
set one_1;
by a turn;
if first.a;
run;
作者: shiyiming    时间: 2004-10-11 15:30
标题: 试试看
data one;
input a b c d;
cards;
1 34 34 2
2 33 33 4
2 33 44 5
3 43 44 3
4 23 23 2
5 34 33 1
5 33 23 2
6 22 33 4
4 34 45 3
;
run;
data one_1;
set one;
if d=2 then turn=1;
if d=5 then turn=2;
if d=1 then turn=3;
if d=4 then turn=4;
if d=3 then turn=5;
run;
proc sort data=one_1;
by a turn;
run;
data one_2;
set one_1;
by a turn;
if first.a;
run;
作者: shiyiming    时间: 2004-10-11 18:24
标题: 谢谢
竟然忘拉 first.*
谢谢各位!




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