BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
thb
Fluorite | Level 6 thb
Fluorite | Level 6

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
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;
thb
Fluorite | Level 6 thb
Fluorite | Level 6

THANK YOU so much! It worked perfectly.

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1134 views
  • 0 likes
  • 2 in conversation