data s;
input id price;
datalines;
100 25
100 60
100 65
100 80
100 91
101 55
101 25
101 85
101 100
;
run;
/* proc sql method : Second max price for each id */
proc sql;
select *
from s as a
where 2=(select distinct price
from s as b
where a.price <= b.price
) ;
quit;
/* Datastep method :Second max price for each id */
data rank;
set s;
run;
proc sort data=s;
by descending id;
run;
data ranking;
set s;
by descending id ;
if first.id then ranks=1;
else ranks+1;
proc print noobs;
run;
data maxvalue ;
set ranking ;
if _n_=2;
proc print ;
run;
Q1.)Here I didn't get correct output for nth max value as of now i want to find second max price for each id how to fix this problem
... View more