<?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: Variable wise nth highest using SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402169#M97638</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;What about ties?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  array test {3} 8 (9,9,1);
  want=largest(2,of test[*]);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 395px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15695i6D32472D23405AC6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 08 Oct 2017 08:07:54 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-10-08T08:07:54Z</dc:date>
    <item>
      <title>Variable wise nth highest using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402054#M97594</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data like below and I want to calculate the nth highest number for the below variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;USA&amp;nbsp; &amp;nbsp; &amp;nbsp; AUS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ENG&lt;/P&gt;&lt;P&gt;1000&amp;nbsp; &amp;nbsp; 2000&amp;nbsp; &amp;nbsp; &amp;nbsp; 500&lt;/P&gt;&lt;P&gt;3000&amp;nbsp; &amp;nbsp; 1000&amp;nbsp; &amp;nbsp; &amp;nbsp; 200&lt;/P&gt;&lt;P&gt;1500&amp;nbsp; &amp;nbsp; 1500&amp;nbsp; &amp;nbsp; &amp;nbsp;1000&lt;/P&gt;&lt;P&gt;2200&amp;nbsp; &amp;nbsp;1100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1500&lt;/P&gt;&lt;P&gt;700&amp;nbsp; &amp;nbsp; &amp;nbsp; 150&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 900&lt;/P&gt;&lt;P&gt;3000&amp;nbsp; &amp;nbsp;1000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;500&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried ranks but I couldn't get the output the way required.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2017 10:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402054#M97594</guid>
      <dc:creator>vijaysas777zx</dc:creator>
      <dc:date>2017-10-07T10:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Variable wise nth highest using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402055#M97595</link>
      <description>&lt;P&gt;Do you want the n'th highest value for each variable or just for one?&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2017 10:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402055#M97595</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-10-07T10:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: Variable wise nth highest using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402058#M97596</link>
      <description>&lt;P&gt;Each variable.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2017 10:42:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402058#M97596</guid>
      <dc:creator>vijaysas777zx</dc:creator>
      <dc:date>2017-10-07T10:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: Variable wise nth highest using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402059#M97597</link>
      <description>&lt;P&gt;And how do you require the output? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2017 10:44:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402059#M97597</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-10-07T10:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: Variable wise nth highest using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402065#M97598</link>
      <description>&lt;P&gt;lets say, I want the second highest of all the variables, The output should be below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;USA&amp;nbsp; &amp;nbsp;AUS&amp;nbsp; &amp;nbsp;ENG&lt;BR /&gt;2200 1500&amp;nbsp; &amp;nbsp;1000&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2017 10:51:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402065#M97598</guid>
      <dc:creator>vijaysas777zx</dc:creator>
      <dc:date>2017-10-07T10:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Variable wise nth highest using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402074#M97600</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/162178"&gt;@vijaysas777zx&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Something like below should work&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input USA AUS ENG;
  datalines;
1000 2000 500
3000 1000 200
1500 1500 1000
2200 1100 1500
700 150 900
3000 1000 500
;
run;

proc rank data=have ties=dense out=ranked;
  var USA AUS ENG;
  ranks _rUSA _rAUS _rENG;
run;

data want(drop=_:);
  set ranked(where=(_rUSA=2));
  set ranked(where=(_rAUS=2));
  set ranked(where=(_rENG=2));
  output;
  stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a lot of countries then you could also transpose your source data to a long structure with only two columns (country, value) and then create the output using Proc Rank with By Group processing.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2017 13:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402074#M97600</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-07T13:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: Variable wise nth highest using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402157#M97634</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input USA AUS ENG;
  datalines;
1000 2000 500
3000 1000 200
1500 1500 1000
2200 1100 1500
700 150 900
3000 1000 500
;
run;
data want;
 set have end=last;
array u{999999} _temporary_;
array a{999999} _temporary_;
array e{999999} _temporary_;

if usa not in u then u{_n_}=usa;
if aus not in a then a{_n_}=aus;
if eng not in e then e{_n_}=eng;

if last then do;
 usa=largest(2,of u{*});
 aus=largest(2,of a{*});
 eng=largest(2,of e{*});
 output;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Oct 2017 06:36:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402157#M97634</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-08T06:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Variable wise nth highest using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402169#M97638</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;What about ties?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  array test {3} 8 (9,9,1);
  want=largest(2,of test[*]);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 395px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15695i6D32472D23405AC6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Oct 2017 08:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402169#M97638</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-08T08:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Variable wise nth highest using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402330#M97676</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;I have already considered about it. Check the code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if usa not in u then u{_n_}=usa;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Oct 2017 12:05:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/402330#M97676</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-09T12:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: Variable wise nth highest using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/403298#M97995</link>
      <description>&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let varlist=low high close;
%let NV=%sysfunc(countw(&amp;amp;varlist,%str( )));
%let ord=4;

%macro ordnals_list(size=);
  %local size;
  %do I=1 %to &amp;amp;size; ,ordnals{_v,&amp;amp;I} %end;
%mend;

options mprint;
data want (DROP=_v);
  array ordnals {&amp;amp;nv,&amp;amp;ord} _temporary_;
  array vars {&amp;amp;NV} &amp;amp;varlist;

  set sashelp.stocks (keep=stock low high close where=(stock='IBM'))  END=EOD;
  do _V=1 to dim(vars);
    if _n_&amp;lt;=&amp;amp;ord then ordnals{_V,_n_}=vars{_V};
    else if vars{_V}&amp;gt;ordnals{_V,1} then call sortn(vars{_V} %ordnals_list(size=&amp;amp;ord));
  end;

  if EOD;
  do _V=1 to dim(vars);
    vars{_V}=ordnals{_V,1};
  END;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Oct 2017 18:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Variable-wise-nth-highest-using-SAS/m-p/403298#M97995</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-11T18:18:28Z</dc:date>
    </item>
  </channel>
</rss>

