data tem;
set tem;
_tem=max(of v1-v3);
array arr v1-v3;
do over arr;
if arr=_tem then V4=_tem||'_'||vname(arr);
end;
drop _tem;
run;
proc print;run;[/quote:1d709]
逻辑很干净利落。
小小建议:其实_tem=max(of v1-v3) 和后面的逻辑导致了重复扫描数组,如果只是求最值,不妨直接求,只需扫描一遍数组:
data tem(keep=v1-v4);
set tem;
array arr v1-v3;
winner = 1;
win_val = arr(1);
do i=2 to dim(arr);
if win_val<arr(i) then do;
winner = i;
win_val= arr(i);
end;
end;
v4 = win_val||'_'||vname(arr(winner));
run;