DATA Step, Macro, Functions and more

Re:Data set, Please reply me ASAP

Reply
N/A
Posts: 0

Re:Data set, Please reply me ASAP

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
Super User
Posts: 5,424

Re:Data set, Please reply me ASAP

Posted in reply to deleted_user
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
N/A
Posts: 0

Re:Data set, Please reply me ASAP

Hi Linus,

Thank you very much for ur reply.

sam
Ask a Question
Discussion stats
  • 2 replies
  • 146 views
  • 0 likes
  • 2 in conversation