3rd highest value

Reply
Frequent Contributor
Posts: 81

3rd highest value

Hi All,

How can I find the 3rd highest(all ways) value in a dataset.

Regards

Anand

Frequent Contributor
Posts: 88

Re: 3rd highest value

Posted in reply to AnandSahu

Hi AnandSahu, Below is the example of finding nth highest salary from given input using Proc SQL.

data salary;

input sal;

cards;

23

12

.

45

0

54

-21

43

;

run; 

%let N=3;
proc sql;
select a.sal from salary a where &N= (select count(distinct sal) from salary b where a.sal<=b.sal);
quit;

Regards,

Tushar J

Respected Advisor
Posts: 3,156

Re: 3rd highest value

Proc Rank seems handy:

proc rank data=sashelp.class out=want(where=(rank=3)) descending ties=dense;

var age;

ranks rank;

run;

Haikuo

Respected Advisor
Posts: 4,173

Re: 3rd highest value

Posted in reply to AnandSahu

Have you already searched the communities here. Similar questions have already been asked and answered multiple times.

Ask a Question
Discussion stats
  • 3 replies
  • 1002 views
  • 1 like
  • 4 in conversation