## if first.id

Solved
Super Contributor
Posts: 464

# if first.id

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

Accepted Solutions
Solution
‎09-21-2016 09:24 AM
Super User
Posts: 23,663

## Re: if first.id

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

All Replies
Solution
‎09-21-2016 09:24 AM
Super User
Posts: 23,663

## Re: if first.id

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

Super Contributor
Posts: 464

## Re: if first.id

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

Super User
Posts: 23,663

## Re: if first.id

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?

Posts: 5,521

## Re: if first.id

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
Super Contributor
Posts: 464

## Re: if first.id

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
• 5 replies
• 445 views
• 0 likes
• 3 in conversation