<?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: proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398480#M96407</link>
    <description>&lt;P&gt;Is this a homework problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would advise to do this in a data step or PROC RANK. It's much simpler.&lt;/P&gt;</description>
    <pubDate>Mon, 25 Sep 2017 10:57:41 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2017-09-25T10:57:41Z</dc:date>
    <item>
      <title>Create ranks using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398473#M96406</link>
      <description>&lt;P&gt;Question : I have a dataset with department names, employee names, salary.&amp;nbsp;I&amp;nbsp;have to&amp;nbsp;find out the 5th largest salary of employee along with its department&amp;nbsp;by using Proc SQL (I know the procedure by using Data step but I want to know by using Proc SQL). Please help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;Dept_Name&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;Emp_name&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;Salary&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;Economics&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;Naveen&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;1070&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;statistics&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;Praveen&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;1157&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;Biology&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;Manju&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;1286&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;marketing&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;Chethan&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;1396&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;Economics&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;vinay&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;1110&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;statistics&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;sanjay&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;1318&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;Biology&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;harshi&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;1376&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;marketing&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;manu V&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;1179&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;Biology&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;manu S&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;1002&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;statistics&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;manu P&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;1442&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 25 Sep 2017 12:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398473#M96406</guid>
      <dc:creator>Naveen1</dc:creator>
      <dc:date>2017-09-25T12:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398480#M96407</link>
      <description>&lt;P&gt;Is this a homework problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would advise to do this in a data step or PROC RANK. It's much simpler.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 10:57:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398480#M96407</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-09-25T10:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398482#M96408</link>
      <description>&lt;P&gt;I want to know in Proc SQl.&lt;/P&gt;&lt;P&gt;I know the procedure in Data step by using rank and (_n_).&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 11:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398482#M96408</guid>
      <dc:creator>Naveen1</dc:creator>
      <dc:date>2017-09-25T11:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398490#M96409</link>
      <description>&lt;P&gt;Post yout trial here and you will be helped for sure. Have you tried solve it by yourself?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 11:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398490#M96409</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2017-09-25T11:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398503#M96412</link>
      <description>&lt;P&gt;Iam not that much good in Proc SQL. When I searched online I could't get exact solution for 5th largest. I got solution for 2nd largest, 3rd largest. So please help me how to get 5th Largest. Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 12:44:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398503#M96412</guid>
      <dc:creator>Naveen1</dc:creator>
      <dc:date>2017-09-25T12:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398506#M96414</link>
      <description>&lt;P&gt;Can you provide a link to the solution for 3rd largest? Why wouldn't that generalize to the 5th largest? Show us your code!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And while it is admirable to try to increase your SQL skills, this really isn't something that you should attempt to do in SQL, since SQL is simply a very poor choice in SAS to do this calculation.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 12:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398506#M96414</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-09-25T12:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398509#M96415</link>
      <description>&lt;P&gt;The above problem is interviewed question. So Iam seeking help in this portal. Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 12:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398509#M96415</guid>
      <dc:creator>Naveen1</dc:creator>
      <dc:date>2017-09-25T12:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398510#M96416</link>
      <description>&lt;P&gt;1/ Sort by Salary (with a SELECT ... ORDER BY if you have to use SQL only)&lt;/P&gt;
&lt;P&gt;2/ Use the monotonic function to get the fifth record.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 12:51:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398510#M96416</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-09-25T12:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398511#M96417</link>
      <description>&lt;P&gt;Can&amp;nbsp;I get elabprated syntax, as I informed earlier I dont have much knowledge on&amp;nbsp; Proc SQL.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 12:53:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398511#M96417</guid>
      <dc:creator>Naveen1</dc:creator>
      <dc:date>2017-09-25T12:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398512#M96418</link>
      <description>&lt;P&gt;You have still not motivated why you want/need to do it in SQL.&lt;/P&gt;
&lt;P&gt;If it's for learning purposes, don't do it, since given the answer already&amp;nbsp;given, there are better ways to do this. Don't learn a less efficient way.&lt;/P&gt;
&lt;P&gt;If you want to learn SQL, there must be tons of other exercises to go about.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 12:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398512#M96418</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-09-25T12:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398517#M96420</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/167244"&gt;@Naveen1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;The above problem is interviewed question. So Iam seeking help in this portal. Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The answer to the interview question is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"It would be easier to do this in a DATA step or using PROC RANK. Doing this in PROC SQL is a very poor choice."&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 13:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398517#M96420</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-09-25T13:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create ranks using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398520#M96421</link>
      <description>&lt;PRE&gt;
Why you want to do this. it is really clumsy for SQL to get the largest n obs.
The following return the 5th largest weight for each sex.



proc sql;
select sex,name,weight,(select count(*) as n  from (select distinct sex,name,weight from sashelp.class) as b
          where b.sex=a.sex and b.weight&amp;lt;=a.weight) as n
 from sashelp.class as a
   where calculated n=5;
quit;

&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Sep 2017 13:07:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398520#M96421</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-09-25T13:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Create ranks using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398533#M96423</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is another way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql outobs=5;&lt;BR /&gt;create table want as&lt;BR /&gt;select * from have&lt;BR /&gt;order by salary desc;&lt;BR /&gt;select * from want&lt;BR /&gt;having salary=min(salary);&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 13:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-ranks-using-SQL/m-p/398533#M96423</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2017-09-25T13:41:56Z</dc:date>
    </item>
  </channel>
</rss>

