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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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