z*****w 发帖数: 118 | 1 Hi, friends,
I have a dataset like this,
1 0
2 0
3 0
4 0
5 150
6 150
7 150
8 0
9 0
10 0
11 0
12 0
13 0
14 150
15 150
16 0
I want to pick every first 150 obs. in each of the 150s groups, such as No.
5 and 14. How can I do that? Thank you very very much . | d*******r 发帖数: 71 | 2 data a;
input id value;
cards;
1 0
2 0
3 0
4 150
5 150
6 150
7 0
8 0
9 150
10 150
11 0
12 150
13 0
14 150
15 150
;
run;
data b;
set a;
retain group 1;
if value=0 then group=1;
if value NE 0 and value=lag(value) then
group+1;
output;
run;
data c;
set b;
if value NE 0 and Group=1;
keep id value;
run;
proc print data=c; run; | z*****w 发帖数: 118 | | f*******e 发帖数: 8 | 4 I do not have SAS at home, try this:
data b(keep = id value);
set a;
retain group 0;
if value = 150 and value ne lag(value) then
do;
group = group +1;
output;
end;
run; |
|