BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ksharp
Super User
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;




raafat
Calcite | Level 5

KSsharp: it works ! thank you very much. Can you please briefly explain you code, of course if you have time 🙂

Ksharp
Super User

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 17 replies
  • 2367 views
  • 2 likes
  • 5 in conversation