BookmarkSubscribeRSS Feed
deleted_user
Not applicable
This is my input data set with 2 variables id and sal and my output should only contain top 5 observations for each id value.
Input Data set:
data sam;
input id sal;
cards;
1 4000
1 4000
1 4000
2 5000
2 6000
2 3000
2 3000
2 3000
2 3000
2 3000
2 3000
3 5000
3 5000
3 5000
3 5000
3 5000
3 5000
3 5000
4 6000
4 6000
run;

Output Dataset:

1 4000
1 4000
1 4000
2 5000
2 6000
2 3000
2 3000
2 3000
3 5000
3 5000
3 5000
3 5000
3 5000
4 6000
4 6000
2 REPLIES 2
LinusH
Tourmaline | Level 20
First, sort you data by id and descending sal.
Then go through your data with a data step, counting no of observations in each by-group and output the first five each. You can accomplish this using first.id and a retain variable.

/Linus
Data never sleeps
deleted_user
Not applicable
Hi Linus,

Thank you very much for ur reply.

sam

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 689 views
  • 0 likes
  • 2 in conversation