Extract Nth highest salary from SALARY table 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;
OUTPUT:
43
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;
OUTPUT:
43
No comments:
Post a Comment