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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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