Is it absolutely necessary to have the data sorted in a ascending order?
Normally you just need the data sorted, reversing to descending would simplify greatly the solution by reducing it to a single pass.
Assuming that YEAR is numeric:
data RESULTS;
set DATA;
if _N_ eq 1 then call symput('MAX_YEAR',put(YEAR,best.));
if not (YEAR >= symgetn('MAX_YEAR') -4) then stop;
run;
Cheers from Portugal.
Daniel Santos @
www.cgd.pt