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

hi guys,

i have  a dataset something like:

 

company_name Employee_id ranking

ibm    100           4

ibm   100           6

ibm   101          5

apple 104       7

apple 104      8

........................

..........................

 

i need to pick the record of the empoyeer with the  highest ranking  :

 

ibm   100           6

ibm   101          5

apple 104      8

 

so was wondering if my logic  is right:

 

proc sort data=have;by comp_name emp_id desecending ranking;

data want;

set have

by comp_name emp_id desecending ranking;

if first.emp_id?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Fastest way is to try it. Best part about most programming is it's quick and easy to try things. 

You should always have a method to test your logic, relying on a forum isn't a good way 🙂

View solution in original post

5 REPLIES 5
Reeza
Super User

Fastest way is to try it. Best part about most programming is it's quick and easy to try things. 

You should always have a method to test your logic, relying on a forum isn't a good way 🙂

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

i did try it and  for small dataset it worked but not  sure  if they were just a  coincidence 🙂

Reeza
Super User

That's why you build test cases.

 

Generate a basic case, then what happens if you have one one record per id, multiple records per id, multiple id's and finally, what if you have ties?

PGStats
Opal | Level 21

Submitting that code will return an error. Before testing your logic, you will need the correct syntax. Keyword desecending should be spelled descending.

 

Good luck.

PG
Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

so  to confirm  that logic works  i created a  temp flag =cats( comp_name, emp_id) and then sorted by tempflag ranking and applied "if first.tempflag" and got the same  result as i got with the above approach so i guess  i was on the  right  track

 

never had such situations so i was not sure 🙂

 

Cheers  

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 2269 views
  • 0 likes
  • 3 in conversation