Hello,
I have the following data table below. I only want to keep the first 3 observation output for each ID and Measure. Any help would be greatly appreciated. Thank you!
data have; input ID Measure Date :mmddyy10. Output; format date mmddyy10.; datalines;
1 A 010117 1
1 A 020117 2
1 A 030117 3
1 A 060118 1
1 A 070118 2
1 A 080118 3
2 A 010116 1
2 A 020116 2
2 A 030116 3
3 A 010116 1
3 A 020116 2
3 A 030116 3
3 B 010116 1
3 B 020116 2
3 B 030116 3
data want; input ID Measure Date :mmddyy10. Output; format date mmddyy10.; datalines;
1 A 010117 1
1 A 020117 2
1 A 030117 3
2 A 010116 1
2 A 020116 2
2 A 030116 3
3 A 010116 1
3 A 020116 2
3 A 030116 3
3 B 010116 1
3 B 020116 2
3 B 030116 3
data have;
input ID Measure $ Date :mmddyy10. Output;
format date mmddyy10.;
datalines;
1 A 010117 1
1 A 020117 2
1 A 030117 3
1 A 060118 1
1 A 070118 2
1 A 080118 3
2 A 010116 1
2 A 020116 2
2 A 030116 3
3 A 010116 1
3 A 020116 2
3 A 030116 3
3 B 010116 1
3 B 020116 2
3 B 030116 3
;
data want;
do _n_=1 by 1 until( last.measure);
set have;
by id measure;
if _n_<=3 then output;
/*else continue;*/
end;
run;
data have;
input ID Measure $ Date :mmddyy10. Output;
format date mmddyy10.;
datalines;
1 A 010117 1
1 A 020117 2
1 A 030117 3
1 A 060118 1
1 A 070118 2
1 A 080118 3
2 A 010116 1
2 A 020116 2
2 A 030116 3
3 A 010116 1
3 A 020116 2
3 A 030116 3
3 B 010116 1
3 B 020116 2
3 B 030116 3
;
data want;
do _n_=1 by 1 until( last.measure);
set have;
by id measure;
if _n_<=3 then output;
/*else continue;*/
end;
run;
THANK YOU so much! It worked perfectly.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.