<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Finding the second max if the data contains two identical max values in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430384#M27762</link>
    <description>&lt;P&gt;can not as the the column names are different &amp;nbsp;for example &amp;nbsp;(sale,compliance....)&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jan 2018 12:25:16 GMT</pubDate>
    <dc:creator>raafat</dc:creator>
    <dc:date>2018-01-24T12:25:16Z</dc:date>
    <item>
      <title>Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430348#M27752</link>
      <description>&lt;P&gt;Hi guyes. I have a problem with finding the second max when i have two identical max values. The code below gives the same max value and colum name, wich is 5 and col3.&amp;nbsp;Is it possible to get the&amp;nbsp;second max as&amp;nbsp;5&amp;nbsp;and col4 instead of col3?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;array&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; col(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) (&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;index_of_1nd=whichn(largest(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,of col(*)),of col(*));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;value_1=vname(col(index_of_1nd));&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;index_of_2nd=whichn(largest(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,of col(*)),of col(*));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;value_2=vname(col(index_of_2nd));&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;run&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 11:10:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430348#M27752</guid>
      <dc:creator>raafat</dc:creator>
      <dc:date>2018-01-24T11:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430359#M27755</link>
      <description>&lt;P&gt;How about adding to the same DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if value_1=value_2 then do;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp; &amp;nbsp;index_of_2nd=whichn(largest(3&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,of col(*)),of col(*));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;value_2=vname(col(index_of_2nd));&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, it's possible that there are three values tied for the max.&amp;nbsp; So you could expand that idea:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do k=2 to dim(col) until (value_1 ne value_2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;index_of_2nd=whichn(largest(&lt;FONT color="#FF0000"&gt;k&lt;/FONT&gt;,of col(*)), of col(*));&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;value_2 = vname(col(index_of_2nd));&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 12:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430359#M27755</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-24T12:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430363#M27756</link>
      <description>&lt;P&gt;Its easy if you keep your data in normalised format, i.e. going down the page rather than across.&amp;nbsp; Simple sort distinct, and take second observation per group.&amp;nbsp; &amp;nbsp;Transposed data is just harder to work with in all senses.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 11:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430363#M27756</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-24T11:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430365#M27757</link>
      <description>&lt;P&gt;that returns col3 and value of 3 for the first max and the second max is col2 and value 2 which i do not understand. what i am interested in is the the first max value=5 and col3 and the second max value 5 and col4&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 11:43:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430365#M27757</guid>
      <dc:creator>raafat</dc:creator>
      <dc:date>2018-01-24T11:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430367#M27758</link>
      <description>&lt;P&gt;First transpose your dataset (always a win), and then do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    groupval,
    your_value,
    otherval
  from transposed
  group by groupval
  having your_value = max(your_value)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jan 2018 11:48:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430367#M27758</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-24T11:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430368#M27759</link>
      <description>&lt;P&gt;Applied to your original data, the process looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
array col(5) (1 4 5 5 4);
run;

proc transpose data=have out=transposed;
var col:;
run;

proc sql;
create table want as
select
  _name_,
  col1
from transposed
having col1 = max(col1)
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See how simple the code becomes, once you turn dumb data into intelligent data (Maxim 33)?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 11:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430368#M27759</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-24T11:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430381#M27760</link>
      <description>&lt;P&gt;i cant not apply your solution kurtbremser as the data updates every week, which means that I get a unique max value sometimes and sometimes identical max value. Furthermore the example i posted is to simple. The real data looks almost like,&lt;/P&gt;&lt;P&gt;DATA want;&lt;BR /&gt;INPUT NAMES $ TEAM $ sa qu comp qa;&lt;BR /&gt;DATALINES;&lt;BR /&gt;Ab alfa 5 3 4 5&lt;BR /&gt;Bb beta 6 7 2 7&lt;BR /&gt;cb sigma 3 4 6 7&lt;BR /&gt;RUN;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which make it harder to transpose.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 13:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430381#M27760</guid>
      <dc:creator>raafat</dc:creator>
      <dc:date>2018-01-24T13:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430383#M27761</link>
      <description>&lt;P&gt;Reverse the order of vaiables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;index_of_1nd=whichn(largest(1,of col(*)),of col5-col1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jan 2018 12:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430383#M27761</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-01-24T12:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430384#M27762</link>
      <description>&lt;P&gt;can not as the the column names are different &amp;nbsp;for example &amp;nbsp;(sale,compliance....)&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 12:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430384#M27762</guid>
      <dc:creator>raafat</dc:creator>
      <dc:date>2018-01-24T12:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430391#M27765</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/92001"&gt;@raafat&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;i cant not apply your solution kurtbremser as the data updates every week, which means that I get a unique max value sometimes and sometimes identical max value. Furthermore the example i posted is to simple. The real data looks almost like,&lt;/P&gt;
&lt;P&gt;DATA want;&lt;BR /&gt;INPUT NAMES $ TEAM $ sa qu comp;&lt;BR /&gt;DATALINES;&lt;BR /&gt;Ab alfa 5 3 4 5&lt;BR /&gt;Bb beta 6 7 2 7&lt;BR /&gt;cb sigma 3 4 6 7&lt;BR /&gt;RUN;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which make it harder to transpose.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Heh?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
INPUT NAMES $ TEAM $ sa qu comp;
DATALINES;
Ab alfa 5 3 4 5
Bb beta 6 7 2 7
cb sigma 3 4 6 7
;
RUN;

proc transpose data=have out=transposed;
by names team;
var sa qu comp;
run;

proc sql;
create table want as
select names, team, _name_, col1
from transposed
group by names, team
having col1 = max(col1)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Edit: added semicolon-only line in the first data step to end the datalines section.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 13:10:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430391#M27765</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-24T13:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430395#M27766</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;

array col(5) (1 4 5 5 4);
temp=largest(1,of col(*));
do i=1 to dim(col);
  if col{i}=temp then do;col{i}=.;index_of_1nd=i;end;
end;
value_1=vname(col(index_of_1nd));

temp=largest(2,of col(*));
do i=1 to dim(col);
  if col{i}=temp then index_of_2nd=i;
end;
value_2=vname(col(index_of_2nd));

drop i temp;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jan 2018 12:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430395#M27766</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-01-24T12:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430396#M27767</link>
      <description>&lt;P&gt;sorry i forgot the last variable &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 13:00:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430396#M27767</guid>
      <dc:creator>raafat</dc:creator>
      <dc:date>2018-01-24T13:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430406#M27769</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/92001"&gt;@raafat&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;sorry i forgot the last variable &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No problem, just add it to the var statement in the proc transpose.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 13:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430406#M27769</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-24T13:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430426#M27774</link>
      <description>&lt;P&gt;Sorry, that can happen before coffee in the morning.&amp;nbsp; Here's a better way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; want;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;array&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; col(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) (&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;array copy (5) _temporary_;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;do k=1 to 5;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&amp;nbsp; copy{k} = col{k};&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;index_of_1nd=whichn(largest(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,of copy(*)),of copy(*));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;value_1=vname(col(index_of_1nd));&lt;/P&gt;
&lt;P&gt;copy{index_of_1nd} = .;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;index_of_2nd=whichn(largest(&lt;FONT color="#ff0000"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,of copy(*)),of copy(*));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;value_2=vname(col(index_of_2nd));&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;run&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 13:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430426#M27774</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-24T13:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430445#M27776</link>
      <description>&lt;P&gt;KSHARP: i do not get the desired output, which is max=5 and col3, max2=5 col4 :). &amp;nbsp;Is possible to delete the column of the first max after finding it, then find the second max simultaneously?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 14:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430445#M27776</guid>
      <dc:creator>raafat</dc:creator>
      <dc:date>2018-01-24T14:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430463#M27780</link>
      <description>&lt;PRE&gt;
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;   /*&amp;lt;--------*/
  end;
end;
drop i temp1 temp2;
run;




&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jan 2018 12:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/430463#M27780</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-01-25T12:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/431739#M27868</link>
      <description>&lt;P&gt;KSsharp: it works ! thank you very much. Can you please briefly explain you code, of course if you have time &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 11:42:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/431739#M27868</guid>
      <dc:creator>raafat</dc:creator>
      <dc:date>2018-01-29T11:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second max if the data contains two identical max values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/431751#M27872</link>
      <description>&lt;P&gt;Actually , It could be rewrited by WHICHN().&lt;/P&gt;
&lt;P&gt;I think it is more readable for you .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
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;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jan 2018 12:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Finding-the-second-max-if-the-data-contains-two-identical-max/m-p/431751#M27872</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-01-29T12:18:58Z</dc:date>
    </item>
  </channel>
</rss>

