<?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: 2nd highest salary of each employee in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552705#M153658</link>
    <description>&lt;P&gt;A simple solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sal; by id descending salary; run;

data need;
   do i = 1 by 1 until(last.id);
      set sal;
      by id;
      if i = 2 then output;
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 21 Apr 2019 16:39:23 GMT</pubDate>
    <dc:creator>KachiM</dc:creator>
    <dc:date>2019-04-21T16:39:23Z</dc:date>
    <item>
      <title>2nd highest salary of each employee</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552614#M153616</link>
      <description>&lt;P&gt;i want to find 2nd highest salary of each employee.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data sal;&lt;BR /&gt;input id name$ salary dt date11.;&lt;BR /&gt;format dt date9.;&lt;BR /&gt;cards;&lt;BR /&gt;101 nick 45000 01jan2019&lt;BR /&gt;101 nick 50000 01feb2019&lt;BR /&gt;101 nick 52000 01mar2019&lt;BR /&gt;101 nick 53000 01apr2019&lt;BR /&gt;102 mark 55000 01jan2019&lt;BR /&gt;102 mark 56000 01feb2019&lt;BR /&gt;102 mark 57000 01mar2019&lt;BR /&gt;102 maek 58000 01apr2019&lt;BR /&gt;;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have done using sql&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select max(T.salary) as sal,T.id from sal&lt;BR /&gt;T inner join (select max(salary) as sal,&lt;BR /&gt;id from sal group by id) TT on T.salary&amp;lt;&amp;gt;TT.sal and&lt;BR /&gt;T.id=TT.id group by T.id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any more simple method in SQL .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Apr 2019 09:25:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552614#M153616</guid>
      <dc:creator>adi121</dc:creator>
      <dc:date>2019-04-20T09:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: 2nd highest salary of each employee</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552615#M153617</link>
      <description>&lt;P&gt;Why not use base sas / data step?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sal;
input id name$ salary dt date11.;
format dt date9.;
cards;
101 nick 45000 01jan2019
101 nick 50000 01feb2019
101 nick 52000 01mar2019
101 nick 53000 01apr2019
102 mark 55000 01jan2019
102 mark 56000 01feb2019
102 mark 57000 01mar2019
102 maek 58000 01apr2019
;run;

proc sort data=sal; by id descending salary; run;

data want;
 set sal;
      by id;
           retain flag;
           if first.id then flag=1;
           else if flag=1 then do;
               output; flag=0;
          end;
run;    &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Apr 2019 10:10:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552615#M153617</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-04-20T10:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: 2nd highest salary of each employee</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552616#M153618</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc univariate data=sal nextrval=2;
by id;
var salary;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Apr 2019 10:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552616#M153618</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-04-20T10:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: 2nd highest salary of each employee</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552620#M153619</link>
      <description>&lt;P&gt;You can add something like the below to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;s code to get a SAS data set with the desired data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods output ExtremeValues=ExtremeValues(where=(HighOrder=3) keep=id High HighOrder);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Apr 2019 11:15:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552620#M153619</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-04-20T11:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: 2nd highest salary of each employee</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552630#M153620</link>
      <description>&lt;P&gt;May I offer small extension to your code? It gives more flexibility.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sal; 
  by id descending salary; 
run;

data want;
  set sal;
  by id;

  retain flag;
  if first.id then flag=1;
              else flag = flag + 1;

  if flag=2 then /* 2 - second, 3 = third, ...*/
  do;
    output; 
    flag=.;
  end;
run;    &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Apr 2019 15:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552630#M153620</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2019-04-20T15:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: 2nd highest salary of each employee</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552631#M153621</link>
      <description />
      <pubDate>Sat, 20 Apr 2019 16:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552631#M153621</guid>
      <dc:creator>justusjillella</dc:creator>
      <dc:date>2019-04-20T16:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: 2nd highest salary of each employee</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552633#M153622</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Capture.JPG" style="width: 387px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28835i06C5F4C10120810F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=sal descending out=ranking ties=dense;
   by id;
	var salary;
    ranks salrank;
run;

proc print n;
  where salrank=2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Apr 2019 17:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552633#M153622</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2019-04-20T17:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: 2nd highest salary of each employee</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552705#M153658</link>
      <description>&lt;P&gt;A simple solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sal; by id descending salary; run;

data need;
   do i = 1 by 1 until(last.id);
      set sal;
      by id;
      if i = 2 then output;
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 Apr 2019 16:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552705#M153658</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-04-21T16:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: 2nd highest salary of each employee</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552815#M153708</link>
      <description>&lt;P&gt;What if there are two same max salary ? Like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id salary&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp;10&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp;10&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;8&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/P&gt;
&lt;P&gt;...........&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 12:50:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552815#M153708</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-04-22T12:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: 2nd highest salary of each employee</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552834#M153716</link>
      <description>&lt;P&gt;I didn't see the ties requirement of OP. There are many answers for that and let OP choose.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 13:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/552834#M153716</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-04-22T13:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: 2nd highest salary of each employee</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/553045#M153759</link>
      <description>&lt;P&gt;To ensure all ties have the same rank I used the Proc rank option ties=dense.&amp;nbsp; In your example data salary 10 is tied at #1 and the answer for the OP (Rank 2) will be salary of 8 for ID 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Capture.JPG" style="width: 217px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28919iE3BEB09FD3BFC5E0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 20:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2nd-highest-salary-of-each-employee/m-p/553045#M153759</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2019-04-22T20:35:35Z</dc:date>
    </item>
  </channel>
</rss>

