I have data that I sorted by Company Year and Salary Descending.
I want to extract only the top 2 salary records for each company and year to a new table.
My data looks like:
Company Year Salary
1 2020 10,000
1 2020 5,000
1 2020 3,000
1 2020 2,000
1 2019 9,000
1 2019 5,000
1 2019 3,000
2 2020 8,000
2 2020 5,000
2 2020 3,000
My desired outcome is my new table will only have the records for 10,000 and 5,000 for company 1 2020, 9,000 and 5,000 for company 1 for 2019, and 8,000 and 5,000 for company 2 in 2020
I tried the following:
proc sort data=temp.own2_for_sample3; by company Year descending salary; run;
data temp.own2_for_sample3; set temp.own2_for_sample3; by company Year salary; if first.year then rnk=0; rnk +1; run;
It appears to work.... however I am afraid that since I'm only doing first.year and not including the first.company it could mess up. Any easy modifications?
Thank you!
... View more