<?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: 3rd highest sal in dense rank in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601144#M76370</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

proc sql;
create table emp 	
  (empno num(6),
   ename char(15), 
   job char(15), 
   mgr num(10),
   hiredate char(15) ,
   sal num(12),
   comm num(6),
   deptno num(10));
quit;


proc sql;
insert into emp values(7369 'SMITH'  'CLERK'           7902  '17-DEC-80'        800         .          20);
insert into emp values(7499 'ALLEN'  'SALESMAN'        7698  '20-FEB-81'       1600        300         30);
insert into emp values(7521 'WARD'   'SALESMAN'        7698  '22-FEB-81'       1250        500         30);
insert into emp values(7566 'JONES'  'MANAGER'         7839  '02-APR-81'       2975         .          20);
insert into emp values(7654 'MARTIN' 'SALESMAN'        7698  '28-SEP-81'       1250       1400         30);
insert into emp values(7698 'BLAKE'  'MANAGER'         7839  '01-MAY-81'       2850         .          30);
insert into emp values(7782 'CLARK'  'MANAGER'         7839  '09-JUN-81'       2450         .          10);
insert into emp values(7788 'SCOTT'  'ANALYST'         7566  '19-APR-87'       3000         .          20);
insert into emp values(7839 'KING'   'PRESIDENT'        .    '17-NOV-81'       5000         .          10);
insert into emp values(7844 'TURNER' 'SALESMAN'        7698  '08-SEP-81'       1500         0          30);
insert into emp values(7876 'ADAMS'  'CLERK'           7788  '23-MAY-87'       1100         .          20);
insert into emp values(7900 'JAMES'  'CLERK'           7698  '03-DEC-81'        950         .          30);
insert into emp values(7902 'FORD'   'ANALYST'         7566  '03-DEC-81'       3000         .          20);
insert into emp values(7934 'MILLER' 'CLERK'           7782  '23-JAN-82'       1300         .          10);
quit;

proc rank data=emp out=want(keep=ranked_salary empno sal
where=(ranked_salary=3))
descending ties=dense;

   var sal ;
   ranks ranked_salary;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 02 Nov 2019 15:00:21 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-11-02T15:00:21Z</dc:date>
    <item>
      <title>3rd highest sal in dense rank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601143#M76369</link>
      <description>&lt;P&gt;Hi&amp;nbsp; ,&lt;/P&gt;&lt;P&gt;Good Evening to all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here I have a emp table so i want find 3rd highest sal using Dense_Rank function&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table emp 	
  (empno num(6),
   ename char(15), 
   job char(15), 
   mgr num(10),
   hiredate char(15) ,
   sal num(12),
   comm num(6),
   deptno num(10));
quit;


proc sql;
insert into emp values(7369 'SMITH'  'CLERK'           7902  '17-DEC-80'        800         .          20);
insert into emp values(7499 'ALLEN'  'SALESMAN'        7698  '20-FEB-81'       1600        300         30);
insert into emp values(7521 'WARD'   'SALESMAN'        7698  '22-FEB-81'       1250        500         30);
insert into emp values(7566 'JONES'  'MANAGER'         7839  '02-APR-81'       2975         .          20);
insert into emp values(7654 'MARTIN' 'SALESMAN'        7698  '28-SEP-81'       1250       1400         30);
insert into emp values(7698 'BLAKE'  'MANAGER'         7839  '01-MAY-81'       2850         .          30);
insert into emp values(7782 'CLARK'  'MANAGER'         7839  '09-JUN-81'       2450         .          10);
insert into emp values(7788 'SCOTT'  'ANALYST'         7566  '19-APR-87'       3000         .          20);
insert into emp values(7839 'KING'   'PRESIDENT'        .    '17-NOV-81'       5000         .          10);
insert into emp values(7844 'TURNER' 'SALESMAN'        7698  '08-SEP-81'       1500         0          30);
insert into emp values(7876 'ADAMS'  'CLERK'           7788  '23-MAY-87'       1100         .          20);
insert into emp values(7900 'JAMES'  'CLERK'           7698  '03-DEC-81'        950         .          30);
insert into emp values(7902 'FORD'   'ANALYST'         7566  '03-DEC-81'       3000         .          20);
insert into emp values(7934 'MILLER' 'CLERK'           7782  '23-JAN-82'       1300         .          10);
quit;


/*how to get 3rd highest salary using Dense_Rank function*/
proc sql;
create table _3rd_highest_dense_rank as
select e.*, dense_rank(), over(order by ,sal desc)
as dense_rank from emp e)
where dense_rank=3;
quit;



&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Nov 2019 14:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601143#M76369</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2019-11-02T14:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: 3rd highest sal in dense rank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601144#M76370</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

proc sql;
create table emp 	
  (empno num(6),
   ename char(15), 
   job char(15), 
   mgr num(10),
   hiredate char(15) ,
   sal num(12),
   comm num(6),
   deptno num(10));
quit;


proc sql;
insert into emp values(7369 'SMITH'  'CLERK'           7902  '17-DEC-80'        800         .          20);
insert into emp values(7499 'ALLEN'  'SALESMAN'        7698  '20-FEB-81'       1600        300         30);
insert into emp values(7521 'WARD'   'SALESMAN'        7698  '22-FEB-81'       1250        500         30);
insert into emp values(7566 'JONES'  'MANAGER'         7839  '02-APR-81'       2975         .          20);
insert into emp values(7654 'MARTIN' 'SALESMAN'        7698  '28-SEP-81'       1250       1400         30);
insert into emp values(7698 'BLAKE'  'MANAGER'         7839  '01-MAY-81'       2850         .          30);
insert into emp values(7782 'CLARK'  'MANAGER'         7839  '09-JUN-81'       2450         .          10);
insert into emp values(7788 'SCOTT'  'ANALYST'         7566  '19-APR-87'       3000         .          20);
insert into emp values(7839 'KING'   'PRESIDENT'        .    '17-NOV-81'       5000         .          10);
insert into emp values(7844 'TURNER' 'SALESMAN'        7698  '08-SEP-81'       1500         0          30);
insert into emp values(7876 'ADAMS'  'CLERK'           7788  '23-MAY-87'       1100         .          20);
insert into emp values(7900 'JAMES'  'CLERK'           7698  '03-DEC-81'        950         .          30);
insert into emp values(7902 'FORD'   'ANALYST'         7566  '03-DEC-81'       3000         .          20);
insert into emp values(7934 'MILLER' 'CLERK'           7782  '23-JAN-82'       1300         .          10);
quit;

proc rank data=emp out=want(keep=ranked_salary empno sal
where=(ranked_salary=3))
descending ties=dense;

   var sal ;
   ranks ranked_salary;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Nov 2019 15:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601144#M76370</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-11-02T15:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: 3rd highest sal in dense rank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601146#M76371</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/33602i0BC3A55EB2A57A76/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Novinosrin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how to fix the error&amp;nbsp; as per my code&amp;nbsp;&lt;/P&gt;&lt;P&gt;please suggest me&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2019 15:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601146#M76371</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2019-11-02T15:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: 3rd highest sal in dense rank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601147#M76372</link>
      <description>&lt;P&gt;Your code looks like a Database specific SQL of some proprietary database like MS SQL Server, Oracle etc. Therefore you wouldn't expect that to work in a Proc SQL(&lt;EM&gt;SAS specific SQL which is proprietary to SAS&lt;/EM&gt;)&amp;nbsp; environment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to use Database specific SQL from/in a SAS environment, I'm afraid you would need to connect to your database using explicit pass through called &lt;EM&gt;&lt;STRONG&gt;Proc SQL pass through&lt;/STRONG&gt;&lt;/EM&gt; within which you may be able to use database specific SQL to work to your needs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I recently had amazing help from these gentlemen&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp; ,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; ,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;in a long thread begging their patience to listen to my emotional rant. I would recommend, do some research online, get your SAS/Database administers to help/collaborate and if any of the above gentlemen et al chimes in, you may be in for a party. Best Regards!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS&lt;/P&gt;
&lt;P&gt;Personal case update, despite their help, I am afraid I couldn't win over bureaucracy. All the best!&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2019 15:19:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601147#M76372</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-11-02T15:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: 3rd highest sal in dense rank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601148#M76373</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;novinosrin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes i am doing&amp;nbsp; homework by oracle emp table&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you for valuable advice&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2019 15:28:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601148#M76373</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2019-11-02T15:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: 3rd highest sal in dense rank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601150#M76374</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, PROC RANK is designed for solving such problems. To stay within the limits of PROC SQL while replicating the result from PROC RANK, you could use a subquery:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select empno, sal, 3 as ranked_salary
from emp a
where (select count(distinct sal) from emp b where b.sal&amp;gt;a.sal)=2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Nov 2019 16:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601150#M76374</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-11-02T16:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: 3rd highest sal in dense rank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601152#M76375</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;Freelance Reinhard&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your valuable reply&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2019 17:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601152#M76375</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2019-11-02T17:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: 3rd highest sal in dense rank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601213#M76378</link>
      <description>&lt;P&gt;Maxim 1: Read the documentation.&lt;/P&gt;
&lt;P&gt;In this case, to see which SQL functions are available in SAS, and how they need to be called. You also have two opening and three closing brackets in your code, so that won't work either.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2019 08:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/3rd-highest-sal-in-dense-rank/m-p/601213#M76378</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-03T08:55:48Z</dc:date>
    </item>
  </channel>
</rss>

