x******l 发帖数: 39 | 1 有一个数据集,比如说下面这个小例子,如何把连续的两个有相同ID,并且rank分别是1
和2的obs找出来放在一个新的数据集中,下面的例子应该找出 obs 3 和 4
obs ID rank
1 1000 1
2 2000 1
3 3000 1
4 3000 2
5 3500 2
6 3500 1
非常感谢! | f********t 发帖数: 117 | 2 select a.id, a.rank, b.rank
from data a, data b
where a.id = b.id
and (a.rank = b.rank + 1 or brank = a.rank +1 )
it theretically should work for 1,2 5.6 | w****g 发帖数: 81 | 3 try this:
proc sort data=old;
by ID;
run;
data new(drop=i);
set old;
by ID;
if first.ID then i=0;
else i+1;
if (last.ID & i=0) | (rank^=1 & rank^=2) then delete;
run; |
|