Help using Base SAS procedures

if first.id

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 440
Accepted Solution

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: 17,831

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 Smiley Happy

View solution in original post


All Replies
Solution
‎09-21-2016 09:24 AM
Super User
Posts: 17,831

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 Smiley Happy

Super Contributor
Super Contributor
Posts: 440

Re: if first.id

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

Super User
Posts: 17,831

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?

Respected Advisor
Posts: 4,649

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

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 Smiley Happy

 

Cheers  

☑ This topic is SOLVED.

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

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