I wants to Pull first 3 observation of each ID in sas -
i wants pull first 3 observation of each id
code using :->
data new; infile vlv dlm = ' '; input x1 x2; run; proc sort data = new ; x1 x2; run; proc print data = new; run; data vis; set new; retain 0; if first.x1 i=0; i+1; run; proc print data = vis;run; data new ; set vis; if lt 2 output; run; title 'output'; proc print data = new; run;
infile using
18 1
18 2
18 4
18 6
18 3
19 7
19 6
19 4
20 66
20 67
20 3
20 7
21 6
21 7
21 8
36 2
36 3
36 3
36 1
i expected output :->
18 1
18 2
18 4
19 7
19 6
19 4
20 66
20 67
20 3
21 6
21 7
21 8
36 2
36 3
36 3
thanks !!
your output criteria incorrect.
if lt 2 output;
it should less 4 if want top 3.
if lt 4 output;
also, although can reuse same dataset name on , on it's not recommended. suggest changing final dataset name new aren't overwriting input data set.
Comments
Post a Comment