NOTICE: code changed for fixing a problem. Sorry !
OK. I misunderstood.
data want;
array col(5) (1 4 5 5 4);
temp1=largest(1,of col(*));
do i=1 to dim(col);
if col{i}=temp1 then do;
col{i}=.;index_of_1nd=i;
value_1=vname(col(index_of_1nd));
leave;
end;
end;
temp2=largest(1,of col(*));
do i=1 to dim(col);
if col{i}=temp2 then do;
index_of_2nd=i;
value_2=vname(col(index_of_2nd));
leave; /*<--------*/
end;
end;
drop i temp1 temp2;
run;
KSsharp: it works ! thank you very much. Can you please briefly explain you code, of course if you have time 🙂
Actually , It could be rewrited by WHICHN().
I think it is more readable for you .
data want;
array col(5) (1 4 5 5 4);
temp=max(of col(*));
idx=whichn(temp,of col(*));
col{idx}=.;
index_of_1nd=idx;
value_1=vname(col(index_of_1nd));
temp=max(of col(*));
idx=whichn(temp,of col(*));
col{idx}=.;
index_of_2nd=idx;
value_2=vname(col(index_of_2nd));
drop temp idx;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.