<?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: 6th max value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703055#M215400</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data max;
input id;
cards;
66
44
23
1
2
3
44
99
4
33
45
88
96
114
553
;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Run this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank
  data=max
  out=want (where=(rank=6))
  descending
  ties=low
;
var id;
ranks rank;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 02 Dec 2020 10:46:23 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-12-02T10:46:23Z</dc:date>
    <item>
      <title>6th max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703005#M215364</link>
      <description>&lt;P&gt;How to find six th max value in a table&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 08:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703005#M215364</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-12-02T08:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: 6th max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703006#M215365</link>
      <description>&lt;P&gt;Do you want to do this for the entire table as a whole or for individual by-groups?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 08:11:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703006#M215365</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-12-02T08:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: 6th max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703008#M215367</link>
      <description>entire table and by groups also</description>
      <pubDate>Wed, 02 Dec 2020 08:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703008#M215367</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-12-02T08:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: 6th max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703014#M215372</link>
      <description>&lt;P&gt;Without much knowledge of your data, I'm going to assume that your data is sorted by the group variable, but not the 'value' variable of interest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if you can use this as a template&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = sashelp.class out = class;
   by sex;
run;

data want;
   if _N_ = 1 then do;
      declare hash h (dataset : 'class(obs=0)', ordered : 'd', multidata : 'Y'); 
      h.definekey ('Height');
      h.definedata (all : 'y');
      h.definedone();
      declare hiter hi ('h');
   end;
 
   do until (last.Sex);                                                      
      set class;
      by Sex;
      h.add();
   end;
 
   do _N_ = 1 by 1 until (hi.next() ne 0 | _N_ = 6); 
   end;

   output;
 
   _N_ = hi.first();                                                             
   _N_ = hi.prev();
   h.clear();    
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Name  Sex Age Height Weight 
Jane  F   12  59.8   84.5 
Henry M   14  63.5   102.5 &lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Dec 2020 08:28:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703014#M215372</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-12-02T08:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: 6th max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703018#M215376</link>
      <description>&lt;P&gt;I think if we decide to sort we can do it by both variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = sashelp.class out = class;
   by sex Height;
run;

data class6th;
  do _N_ = 1 by 1 until(last.sex);
    set class;
    by Sex;
    if _N_ = 6 then output; 
  end;
run;

proc print data = class6th;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And for "no sorting at all" case hash-of-hashes could be useful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 08:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703018#M215376</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-12-02T08:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: 6th max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703020#M215377</link>
      <description>&lt;P&gt;The example above handles the by-group case in a single pass.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the entire table, find an example online. There are tons. For example, Proc Rank is a fine tool for this.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 08:35:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703020#M215377</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-12-02T08:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: 6th max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703021#M215378</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;agree &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 08:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703021#M215378</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-12-02T08:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: 6th max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703033#M215384</link>
      <description>&lt;P&gt;To find global N-th on table without sorting and groups it could be like that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let size = 6;
data nosort6th;
  array a[&amp;amp;size.] _temporary_;

  do _N_ = 1 to &amp;amp;size.;
    set class nobs = nobs;
    a[_N_] = Height;
  end;

  call sortn(of a[*]);

  if nobs &amp;gt; &amp;amp;size. then
    do until(eof);
      set class(firstobs=%eval(&amp;amp;size.+1)) end=eof;
      if height&amp;gt;a[1] then
        do;
          a[1] = height;
          call sortn(of a[*]);
        end;
    end;

  value&amp;amp;size. = a[1];

  put value&amp;amp;size. =;
  keep value&amp;amp;size.;
  output;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But `&amp;amp;size.` must be &amp;lt;= `nobs`.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 08:54:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703033#M215384</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-12-02T08:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: 6th max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703044#M215392</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data max;
input id;
cards;
66
44
23
1
2
3
44
99
4
33
45
88
96
114
553
;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Dec 2020 09:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703044#M215392</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2020-12-02T09:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: 6th max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703051#M215398</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data max;
input id;
cards;
66
44
23
1
2
3
44
99
4
33
45
88
96
114
553
;
run;

%let data = max;
%let vaiable = id;
%let size = 6;

data nosort6th;
  array a[&amp;amp;size.] _temporary_;

  do _N_ = 1 to &amp;amp;size.;
    set &amp;amp;data. nobs = nobs;
    a[_N_] = &amp;amp;vaiable.;
  end;

  call sortn(of a[*]);

  if nobs &amp;gt; &amp;amp;size. then
    do until(eof);
      set &amp;amp;data.(firstobs=%eval(&amp;amp;size.+1)) end=eof;
      if &amp;amp;vaiable. &amp;gt; a[1] then
        do;
          a[1] = &amp;amp;vaiable.;
          call sortn(of a[*]);
        end;
    end;

  value&amp;amp;size. = a[1];

  put value&amp;amp;size. =;
  keep value&amp;amp;size.;
  output;
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Dec 2020 10:33:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703051#M215398</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-12-02T10:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: 6th max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703055#M215400</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data max;
input id;
cards;
66
44
23
1
2
3
44
99
4
33
45
88
96
114
553
;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Run this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank
  data=max
  out=want (where=(rank=6))
  descending
  ties=low
;
var id;
ranks rank;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Dec 2020 10:46:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/6th-max-value/m-p/703055#M215400</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-02T10:46:23Z</dc:date>
    </item>
  </channel>
</rss>

