<?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 How to find the second highest value in given data? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/409652#M100083</link>
    <description>&lt;P&gt;data second;&lt;BR /&gt;input name$ number;&lt;BR /&gt;cards;&lt;BR /&gt;aravind 98&lt;BR /&gt;kiran 49&lt;BR /&gt;lahari 58&lt;BR /&gt;ahalya 97&lt;BR /&gt;amith 69&lt;BR /&gt;ankit 97&lt;BR /&gt;abhhi 70&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In data steps and proc sql ?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Nov 2017 21:24:43 GMT</pubDate>
    <dc:creator>rajeshalwayswel</dc:creator>
    <dc:date>2017-11-01T21:24:43Z</dc:date>
    <item>
      <title>How to find the second highest value in given data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/409652#M100083</link>
      <description>&lt;P&gt;data second;&lt;BR /&gt;input name$ number;&lt;BR /&gt;cards;&lt;BR /&gt;aravind 98&lt;BR /&gt;kiran 49&lt;BR /&gt;lahari 58&lt;BR /&gt;ahalya 97&lt;BR /&gt;amith 69&lt;BR /&gt;ankit 97&lt;BR /&gt;abhhi 70&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In data steps and proc sql ?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 21:24:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/409652#M100083</guid>
      <dc:creator>rajeshalwayswel</dc:creator>
      <dc:date>2017-11-01T21:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the second highest value in given data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/409655#M100086</link>
      <description>&lt;P&gt;proc sort data=have; by descending number;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have (obs=2 firstobs=2);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or see the SAS PROC UNIVARIATE/PROC MEANS on isolating the top X values or the Xth value. There's an example in the documentation for each of the procedures.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 21:34:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/409655#M100086</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-01T21:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the second highest value in given data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/409657#M100087</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data second;
input name$ number;
cards;
aravind 98
kiran 49
lahari 58
ahalya 97
amith 69
ankit 97
abhhi 70
;
run;

proc sql print;
    
   create table tmp1 as
	select name,number
	  from second
	order by number desc;

	create table tmp2 as
	   select name, number, monotonic() as rank
	    from tmp1
	    where calculated rank = 2;

	create table want as
	   select *
	     from tmp1 
		   where number in (select number from tmp2);
	 
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Nov 2017 01:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/409657#M100087</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2017-11-02T01:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the second highest value in given data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/409668#M100093</link>
      <description>&lt;P&gt;With each incoming observation, you can just maintain a record of the 1st and 2nd maximum values and their corresponding observation numbers.&amp;nbsp; Then, at the end of the dataset, just reread the observation number (_p2 below) that corresponds to the 2nd largest value (_max2):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data second;
input name$ number;
cards;
aravind 98
kiran 49
lahari 58
ahalya 97
amith 69
ankit 97
abhhi 70
;
run;

data want (drop=_:);
  set second end=eod;
  retain _max1 _max2  _p1 _p2 .;

  if number&amp;gt;_max1 then do;
    _max2=_max1;  _p2=_p1;
    _max1=number; _p1=_n_;
  end;
  else if number&amp;gt;_max2 then do;
    _max2=number; _p2=_n_;
  end;

  if eod ;
  set second point=_p2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Nov 2017 22:34:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/409668#M100093</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-11-01T22:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the second highest value in given data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/409676#M100097</link>
      <description>&lt;P&gt;&lt;BR /&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql outobs=1; 
  create table WANT1 as 
  select * 
  from HAVE 
  having NUMBER ne max(NUMBER) 
  order by NUMBER desc ;
quit; 

data WANT2;
  if 0 then set HAVE;
  dcl hash HT(dataset:'HAVE', ordered:'descending');
  HT.definekey('NUMBER');
  HT.definedata('NAME','NUMBER');
  HT.definedone();
  dcl hiter iter('HT');
  RC=iter.first();
  RC=iter.next();
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 23:16:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/409676#M100097</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-11-01T23:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the second highest value in given data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/534769#M146798</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc transpose data= second out=trans_second;

run;

data max;

set trans_second;

max=largest(2,of col1-col7);

run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 10:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/534769#M146798</guid>
      <dc:creator>subhroster</dc:creator>
      <dc:date>2019-02-12T10:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the second highest value in given data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/534778#M146801</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/174522"&gt;@rajeshalwayswel&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or Proc Rank which lets you define how to deal with ties.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank
    data=second
    ties=dense descending
    out=want(where=(number_rank=2))
    ;
  var number;
  ranks number_rank;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2019 12:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/534778#M146801</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-12T12:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the second highest value in given data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/647261#M193686</link>
      <description>&lt;P&gt;Brilliant!&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 22:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/647261#M193686</guid>
      <dc:creator>Recep</dc:creator>
      <dc:date>2020-05-12T22:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the second highest value in given data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/839202#M331826</link>
      <description>Can you please explain what is happening in table want? Thank You.</description>
      <pubDate>Tue, 18 Oct 2022 14:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-the-second-highest-value-in-given-data/m-p/839202#M331826</guid>
      <dc:creator>ketan_korde</dc:creator>
      <dc:date>2022-10-18T14:39:10Z</dc:date>
    </item>
  </channel>
</rss>

