<?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: How to find out third largest/ smallest number in dataset? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357911#M84071</link>
    <description>&lt;P&gt;Wooow. Very simple &amp;amp; superb technique!!! Thanks!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 May 2017 14:21:55 GMT</pubDate>
    <dc:creator>ImPrem</dc:creator>
    <dc:date>2017-05-11T14:21:55Z</dc:date>
    <item>
      <title>How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357549#M83955</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a student learning Base SAS Programming. My trainer gave me an assignment to find out the largest or smallest number from dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is easy in excel, we can use "&lt;STRONG&gt;large&lt;/STRONG&gt;" function to find out the same. I don't have any clue on Base SAS. Kindly help me out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ex:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data EmployeeSalary;&lt;/P&gt;&lt;P&gt;input empid $ name $ salary comma6. ;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;RY4672 arun 57,899&lt;/P&gt;&lt;P&gt;TU5789 Varun 24,769&lt;/P&gt;&lt;P&gt;YI5628 Vikas 68,588&lt;/P&gt;&lt;P&gt;GU5879 Ajay 38,589&lt;/P&gt;&lt;P&gt;FL5728 Shiva 42,699&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 16:14:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357549#M83955</guid>
      <dc:creator>ImPrem</dc:creator>
      <dc:date>2017-05-10T16:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357552#M83956</link>
      <description>&lt;P&gt;Take a look at&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002154865.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002154865.htm&lt;/A&gt; and&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002154862.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002154862.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 16:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357552#M83956</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-10T16:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357558#M83961</link>
      <description>&lt;P&gt;Thank you very much for your quick response.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don't mind, kindly help me out with code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 16:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357558#M83961</guid>
      <dc:creator>ImPrem</dc:creator>
      <dc:date>2017-05-10T16:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357565#M83962</link>
      <description>&lt;P&gt;There is more than one answer. Here is one way it could be used:&lt;/P&gt;
&lt;PRE&gt;Data EmployeeSalary;
  input empid $ name $ salary comma6. ;
  cards;
RY4672 arun 57,899
TU5789 Varun 24,769
YI5628 Vikas 68,588
GU5879 Ajay 38,589
FL5728 Shiva 42,699
run;

data want (keep=salaries third_smallest);
  set EmployeeSalary end=eof;
  array salaries(9999) _temporary_;
  salaries(_n_)=salary;
  if eof then do;
    third_smallest=smallest(3,of salaries(*));
    output;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 16:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357565#M83962</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-10T16:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357567#M83963</link>
      <description>&lt;P&gt;I'm a begineer (Base SAS). For me, its very difficult to understand the sas code. I heard SAS is very simple tool when compare to Excel. But your code was very difficult to understand. Kindly give me very simple SAS code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output needs to be printed using proc print.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 16:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357567#M83963</guid>
      <dc:creator>ImPrem</dc:creator>
      <dc:date>2017-05-10T16:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357574#M83964</link>
      <description>&lt;P&gt;Sorry, I don't know of an easy way to do what you want. The code I suggested put all of the salaries in an array and then found the third smallest one. You can use proc print to print the resulting file/answer&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An alternative, but more complex, is to transpose the file. That is, put all of the salaries on one line. e.g.:&lt;/P&gt;
&lt;PRE&gt;Data EmployeeSalary;
  input empid $ name $ salary comma6. ;
  cards;
RY4672 arun 57,899
TU5789 Varun 24,769
YI5628 Vikas 68,588
GU5879 Ajay 38,589
FL5728 Shiva 42,699
run;

proc transpose data=EmployeeSalary out=wide;
  var salary;
run;

data want(keep=third_smallest);
  set wide;
  third_smallest=smallest(3,of col:);
run;

proc print data=want;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 17:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357574#M83964</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-10T17:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357578#M83966</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/143255"&gt;@ImPrem&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I'm a begineer (Base SAS). For me, its very difficult to understand the sas code. I heard SAS is very simple tool when compare to Excel. But your code was very difficult to understand. Kindly give me very simple SAS code.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you heard that SAS was very simple, then I suggest that this is incorrect. SAS can get complicated when doing complicated tasks. I doubt you will find simpler code in a data step, otherwise Art would have provided it.&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 17:09:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357578#M83966</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-05-10T17:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357581#M83968</link>
      <description>&lt;P&gt;Exactly how you want the results can have a big difference on an approach. If I just wanted to know the value with out the result in a data set I would start with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc univariate data=employeesalary;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; var salary.&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the results will be a list of the 5 largest and 5 smallest values of the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or just largest and smallest:&lt;/P&gt;
&lt;P&gt;Proc means data=employeesalary min max;&lt;/P&gt;
&lt;P&gt;var salary;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Means has some options to get top and bottom 3 as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 17:12:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357581#M83968</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-05-10T17:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357600#M83981</link>
      <description>&lt;P&gt;Superb!! Your SAS code is very simple &amp;amp; easy to learn for begineers like me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output suppose to print the entire coloumn. I mean "Name Empid &amp;amp; Salary"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As well as if replace smallest to largest syntax code is not executing.. help me out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 17:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357600#M83981</guid>
      <dc:creator>ImPrem</dc:creator>
      <dc:date>2017-05-10T17:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357601#M83982</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/143255"&gt;@ImPrem&lt;/a&gt;&amp;nbsp;You're asking us to do your assignment rather than taking the time to learn. And your instructor will know because you're expected to use the techniques taught in class and the solutions we provide may not align with what you were taught and the type of solution you should be implementing. If you want to learn SAS invest the time to learn, if you're just trying to pass a course for some reason then good luck.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 17:44:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357601#M83982</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-10T17:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357607#M83985</link>
      <description>&lt;P&gt;Thank you for your kind friendly advise!! Today&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;taught me the new technique to do in different way! I'm amazed! Looking &amp;nbsp;forward to do the same task in a different way. So, i will also learn from expert like you people.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;Kindly guide me with some study materials for begineers like me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once again thank you very much!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 17:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357607#M83985</guid>
      <dc:creator>ImPrem</dc:creator>
      <dc:date>2017-05-10T17:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357621#M83995</link>
      <description>&lt;P&gt;Support.sas.com/training/tutorial&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://stats.idre.ucla.edu/sas/modules/" target="_blank"&gt;http://stats.idre.ucla.edu/sas/modules/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 18:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357621#M83995</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-10T18:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357868#M84058</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Why not use PROC SORT and pick up the third obs , proc transpose is not efficient .&lt;/P&gt;
&lt;P&gt;BTW, Congratulations! you surpass&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;,become No.1 solution sas user.&lt;/P&gt;
&lt;P&gt;Since you both come from Canada, Have you both met before ?&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 13:00:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357868#M84058</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-05-11T13:00:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357911#M84071</link>
      <description>&lt;P&gt;Wooow. Very simple &amp;amp; superb technique!!! Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 14:21:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357911#M84071</guid>
      <dc:creator>ImPrem</dc:creator>
      <dc:date>2017-05-11T14:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357914#M84072</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;This can be easiest solution to find third lowest number in dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA XY;&lt;BR /&gt;INPUT Dept $ Salary;&lt;BR /&gt;datalines;&lt;BR /&gt;AA 100&lt;BR /&gt;AA 400&lt;BR /&gt;AA 200&lt;BR /&gt;AA 300&lt;BR /&gt;BB 222&lt;BR /&gt;BB 111&lt;BR /&gt;BB 444&lt;BR /&gt;BB 333&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;BR /&gt;PROC SORT DATA=XY ;&lt;BR /&gt;BY Dept Salary;RUN;&lt;/P&gt;&lt;P&gt;data xy1;&lt;BR /&gt;set XY;&lt;BR /&gt;by Dept Salary;&lt;BR /&gt;if first.dept=1 then n=0;&lt;BR /&gt;n+1;&lt;BR /&gt;if n=3 then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hope this helps.&lt;/P&gt;&lt;P&gt;I am working upon to&amp;nbsp;write the code for third largest as well.&lt;/P&gt;&lt;P&gt;guess, proc sql can do this for third largest easily.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 14:26:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357914#M84072</guid>
      <dc:creator>thisisneeraj</dc:creator>
      <dc:date>2017-05-11T14:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357917#M84073</link>
      <description>&lt;P&gt;Your sas code wont execute the expected output.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here you go...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=EmployeeSalary out=emp1;&lt;BR /&gt;by descending sal; &amp;nbsp;/ * keep "by sal" &amp;nbsp;- lowest 3rd Value /&lt;BR /&gt;run;&lt;BR /&gt;proc print data=emp1 (firstobs=3 obs=3);&amp;nbsp;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Very simple logic dude!!!! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 14:32:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357917#M84073</guid>
      <dc:creator>ImPrem</dc:creator>
      <dc:date>2017-05-11T14:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357921#M84075</link>
      <description>&lt;P&gt;hi All,&lt;/P&gt;&lt;P&gt;Posting the finally completed answer:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets prepare the data first:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA XY;&lt;BR /&gt;INPUT Dept $ Salary;&lt;BR /&gt;datalines;&lt;BR /&gt;AA 100&lt;BR /&gt;AA 400&lt;BR /&gt;AA 200&lt;BR /&gt;AA 300&lt;BR /&gt;BB 222&lt;BR /&gt;BB 111&lt;BR /&gt;BB 444&lt;BR /&gt;BB 333&lt;BR /&gt;AA 500&lt;BR /&gt;AA 600&lt;BR /&gt;AA 700&lt;BR /&gt;BB 555&lt;BR /&gt;BB 666&lt;BR /&gt;BB 777&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) For third smallest:&amp;nbsp;&lt;BR /&gt;PROC SORT DATA=XY ;&lt;BR /&gt;BY Dept Salary;RUN;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data ThirdSmallest;&lt;BR /&gt;set XY;&lt;BR /&gt;by Dept Salary;&lt;BR /&gt;if first.dept=1 then n=0;&lt;BR /&gt;n+1;&lt;BR /&gt;if n=3 then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) For third highest:&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SORT DATA=XY ;BY Dept descending Salary;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC RANK DATA=XY descending OUT=XYRanked ;&lt;BR /&gt;var Salary; by dept; ranks SalaryRank;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data thirdLargest;&lt;BR /&gt;set XYRanked;&lt;BR /&gt;if SalaryRank=3;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hope this helps .&lt;/P&gt;&lt;P&gt;Thanks a lot .&lt;/P&gt;&lt;P&gt;Please let me know for any more inputs in this regards.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 14:46:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357921#M84075</guid>
      <dc:creator>thisisneeraj</dc:creator>
      <dc:date>2017-05-11T14:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357955#M84088</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;: I didn't know we were having a contest but, no, I could never keep up with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;. Yes, while we live almost&amp;nbsp;&lt;STRONG&gt;3,364 km apart,&amp;nbsp;&lt;/STRONG&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;and I have met at previous SGFs. As for the transpose solution, it wasn't ,my first choice! I only offered it because&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/143255"&gt;@ImPrem&lt;/a&gt;&amp;nbsp;asked for an alternative to the one I actually presented.&lt;/P&gt;
&lt;P&gt;However, since you mentioned efficiency, the code I originally proposed, runs almost 3 times faster than using sort. I ran a rather simple test:&lt;/P&gt;
&lt;PRE&gt;data weight;
  do i=1 to 1000000;
    weight=ranuni(927);
    output;
  end;
run;

data want;
  set weight end=eof;
  array weights(1000000) _temporary_;
  weights(_n_)=weight;
  if eof then do;
    third_smallest=smallest(3,of weights(*));
    output;
  end;
run;

proc print data=want;
run;

proc sort data=weight out=temp;
by weight;
run;

proc print data=temp (firstobs=3 obs=3); 
run;
&lt;/PRE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/143255"&gt;@ImPrem&lt;/a&gt;: Your final solution has a critical error in it. You sort by descending, thus put the records with the largest values at the top, but then print the 3rd largest&amp;nbsp;and call it the third smallest. However, it was nice to see that you really do appear to be trying to learn SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 15:32:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/357955#M84088</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-11T15:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/358211#M84154</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I don't think you are contender for me. I think you are partner for me . We both have the same papers in SGF.&lt;/P&gt;
&lt;P&gt;Most time I agree with your solution, and of course learn a lot from you too.&lt;/P&gt;
&lt;P&gt;I would like to say welcome back sas forum.&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 12:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/358211#M84154</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-05-12T12:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out third largest/ smallest number in dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/358265#M84163</link>
      <description>&lt;P&gt;How would you find department wise third highest salary ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your answer will not work in that case...&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your answer is so much at basic level my friend ...!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 15:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-third-largest-smallest-number-in-dataset/m-p/358265#M84163</guid>
      <dc:creator>thisisneeraj</dc:creator>
      <dc:date>2017-05-12T15:37:12Z</dc:date>
    </item>
  </channel>
</rss>

