Hi Everyone,
My data has date, time, ID and value.
For each row, say date=1, time =12 and ID = 1, I want to find the 1st highest, 2nd highest and 3rd highest values for that id, of that date, and up to that time (<12).
The illustration of that row at the end.
Can you please help me?
Thank you,
HHC
data have;
input date time ID value;
cards;
0 1 1 88888
0 1 9 585
1 1 1 999
1 2 1 7
1 3 1 3
1 4 1 101
1 7 1 102
1 9 1 12
1 12 1 9999
1 13 1 105
1 14 1 1
2 12 1 5
2 13 1 8
1 2 124
1 2 11
1 2 9999
1 2 9
;
data temp; set have;
if id=1 and date=1 and time<12 ;run;
proc sort data=temp; by id descending value;run;
*pick to 3;
data temp; set temp;
if _N_<=3;
run;
*spread horizontally;
proc transpose data=temp out=want (drop = _NAME_);
by date id;
var value;run;
data want; set want;
rename col1=top1 col2=top2 col3=top3;
time=12;run;
... View more