A little late in the game, but here is a single-pass solution, which gets the 4th highest values for HIGH LOW and CLOSE for IBM stocks in sashelp.stocks:
%let varlist=low high close;
%let NV=%sysfunc(countw(&varlist,%str( )));
%let ord=4;
%macro ordnals_list(size=);
%local size;
%do I=1 %to &size; ,ordnals{_v,&I} %end;
%mend;
options mprint;
data want (DROP=_v);
array ordnals {&nv,&ord} _temporary_;
array vars {&NV} &varlist;
set sashelp.stocks (keep=stock low high close where=(stock='IBM')) END=EOD;
do _V=1 to dim(vars);
if _n_<=&ord then ordnals{_V,_n_}=vars{_V};
else if vars{_V}>ordnals{_V,1} then call sortn(vars{_V} %ordnals_list(size=&ord));
end;
if EOD;
do _V=1 to dim(vars);
vars{_V}=ordnals{_V,1};
END;
run;
... View more