<?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 proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql/m-p/246594#M309372</link>
    <description>&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id Salary;&lt;BR /&gt;cards;&lt;BR /&gt;101 1000&lt;BR /&gt;102 2000&lt;BR /&gt;103 1000&lt;BR /&gt;104 3000&lt;BR /&gt;105 3000&lt;BR /&gt;106 4000&lt;/P&gt;&lt;P&gt;107 2000&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;wanted to find id and salary which is 3rd max value using sql??&lt;/P&gt;&lt;P&gt;in this case result should be 102, 107 with 2000 salary which is 3rd maximum&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jan 2016 12:19:54 GMT</pubDate>
    <dc:creator>vandhan</dc:creator>
    <dc:date>2016-01-28T12:19:54Z</dc:date>
    <item>
      <title>proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql/m-p/246594#M309372</link>
      <description>&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id Salary;&lt;BR /&gt;cards;&lt;BR /&gt;101 1000&lt;BR /&gt;102 2000&lt;BR /&gt;103 1000&lt;BR /&gt;104 3000&lt;BR /&gt;105 3000&lt;BR /&gt;106 4000&lt;/P&gt;&lt;P&gt;107 2000&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;wanted to find id and salary which is 3rd max value using sql??&lt;/P&gt;&lt;P&gt;in this case result should be 102, 107 with 2000 salary which is 3rd maximum&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 12:19:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql/m-p/246594#M309372</guid>
      <dc:creator>vandhan</dc:creator>
      <dc:date>2016-01-28T12:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql/m-p/246600#M309373</link>
      <description>&lt;P&gt;Well, you can't exactly. You could use the undocumented/unsupported&amp;nbsp;function monotonic() (gives you record no) which&amp;nbsp;could be applied after a sort.&lt;/P&gt;
&lt;P&gt;But why are you fixed with SQL?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 12:45:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql/m-p/246600#M309373</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-01-28T12:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql/m-p/246608#M309374</link>
      <description>&lt;P&gt;Post an example of your exact data, as per the duplicate post, there is more than one variable. &amp;nbsp;I would suggest a datastep, where you have an array of 3, each one containing the max e.g:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array results{6,3} 8.;
  retain results1-results3;
  array items{6} your_variable1-your_variable6;
  do i=1 to 6;
    if items{i} &amp;gt; results{i,1} then results{i,1}=items{i};
    else if items{i} &amp;gt; results{i,2} then results{i,2}=items{i};
    else if items{i} &amp;gt; results{i,3} then results{i,3}=items{i};
  end;
run;
  &lt;/PRE&gt;
&lt;P&gt;You will then have a 6 * 3 array of variables which contain varnumber (1-6) of the top 3 results. &amp;nbsp;You can use this how you wish, maybe by a second datastep (or set command) which outputs when the value=the corresponding array element. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 13:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql/m-p/246608#M309374</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-01-28T13:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql/m-p/246631#M309375</link>
      <description>1 sql step or can this be processed in a couple of steps?</description>
      <pubDate>Thu, 28 Jan 2016 14:49:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql/m-p/246631#M309375</guid>
      <dc:creator>BMiller</dc:creator>
      <dc:date>2016-01-28T14:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql/m-p/246632#M309376</link>
      <description>One or many.&amp;nbsp;&lt;BR /&gt;</description>
      <pubDate>Thu, 28 Jan 2016 14:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql/m-p/246632#M309376</guid>
      <dc:creator>vandhan</dc:creator>
      <dc:date>2016-01-28T14:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql/m-p/246645#M309377</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can do it in 2 using a macro assignment:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select distinct salary&lt;BR /&gt;into :top1 - :top3&lt;BR /&gt;from have&lt;BR /&gt;order by salary desc&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select * from have&lt;BR /&gt;where salary = &amp;amp;top3.&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 15:28:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql/m-p/246645#M309377</guid>
      <dc:creator>BMiller</dc:creator>
      <dc:date>2016-01-28T15:28:05Z</dc:date>
    </item>
  </channel>
</rss>

