<?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 Help in Rank function -SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399169#M96652</link>
    <description>&lt;P&gt;&lt;BR /&gt;I know Rank function in SAS EG. But I am trying to get the data from Oracle. So I am using PROC SQL.&lt;BR /&gt;Given Data&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; Status &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; completed &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 09-SEP-16&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;null &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08-SEP-16&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inprogress &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07-JUL-16&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NotCompleted &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07-JUL-16&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;InProgress &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;09-sep-16&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; completed &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;09-sep-16&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; null &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;09-sep-16&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; n/a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 05-AUG-16&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Failed &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10-JUN-16&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;BR /&gt;Connect to oracle..&lt;BR /&gt;create table x as select * from connection to oracle&lt;/P&gt;&lt;P&gt;select&lt;BR /&gt;id, status, date,&lt;BR /&gt;row_number() over(partition by id order by date desc) seq&lt;BR /&gt;from y where seq=1;&lt;BR /&gt;quit;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;In the ID 2, I need the output as completed instead of Inprogress or null for the date 09-sep-16.&lt;BR /&gt;Is there any way I can able to get 'completed' status as my result?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 27 Sep 2017 13:58:02 GMT</pubDate>
    <dc:creator>Kalai2008</dc:creator>
    <dc:date>2017-09-27T13:58:02Z</dc:date>
    <item>
      <title>Help in Rank function -SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399169#M96652</link>
      <description>&lt;P&gt;&lt;BR /&gt;I know Rank function in SAS EG. But I am trying to get the data from Oracle. So I am using PROC SQL.&lt;BR /&gt;Given Data&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; Status &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; completed &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 09-SEP-16&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;null &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08-SEP-16&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Inprogress &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07-JUL-16&lt;BR /&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NotCompleted &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07-JUL-16&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;InProgress &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;09-sep-16&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; completed &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;09-sep-16&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; null &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;09-sep-16&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; n/a &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 05-AUG-16&lt;BR /&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Failed &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10-JUN-16&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;BR /&gt;Connect to oracle..&lt;BR /&gt;create table x as select * from connection to oracle&lt;/P&gt;&lt;P&gt;select&lt;BR /&gt;id, status, date,&lt;BR /&gt;row_number() over(partition by id order by date desc) seq&lt;BR /&gt;from y where seq=1;&lt;BR /&gt;quit;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;In the ID 2, I need the output as completed instead of Inprogress or null for the date 09-sep-16.&lt;BR /&gt;Is there any way I can able to get 'completed' status as my result?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 13:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399169#M96652</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-09-27T13:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: Help in Rank function -SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399191#M96666</link>
      <description>&lt;P&gt;For that example input data what should the result look like?&lt;/P&gt;
&lt;P&gt;And what is the rule for setting any specific "inprogess"&amp;nbsp; to completed? Is it every instance or is it conditional in any way? Same question for "null".&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 14:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399191#M96666</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-27T14:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Help in Rank function -SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399213#M96675</link>
      <description>&lt;P&gt;Thank you for checking!&lt;BR /&gt;The data I have provided is sample only. For ID2, I only need the status as 'completed'.&lt;BR /&gt;The rule is on the same date, let say on 09-SEP-16, If I see any status ..there can be 4 or 5 status, But whenever I see 'completed' in the (recent date only), my query should pick it. If I see 'completed' status on the 08-sep-16, I don't want them. That's why I am using the row_over function to capture the recent date status.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't want any rule to change the status from 'inprogress' to 'completed'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result should look like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Status &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; completed &amp;nbsp; &amp;nbsp;09-sep-16&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;completed &amp;nbsp; &amp;nbsp; 09-sep-16&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp;inprogress &amp;nbsp; &amp;nbsp; &amp;nbsp;05-sep-16 .....&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 15:04:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399213#M96675</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-09-27T15:04:56Z</dc:date>
    </item>
    <item>
      <title>Re: Help in Rank function -SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399219#M96678</link>
      <description>Since your are using explicit pass through it makes sence to have the full query there. &lt;BR /&gt;And the you are probably better off asking this question on an Oracle forum.</description>
      <pubDate>Wed, 27 Sep 2017 15:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399219#M96678</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-09-27T15:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: Help in Rank function -SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399253#M96689</link>
      <description>&lt;P&gt;I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt; that if you can do a query in Oracle and pass the result to SAS (or however that is done) that sounds like a better path.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having said that, I present this cheat of a workaround:&lt;/P&gt;
&lt;P&gt;*edited because I messed up a capitalization*&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* get in some data;
Data project_status;
  input id:$1. status:$13. mydate:ddmmyy10.;
  datalines;
1 completed 090916
1 null 080916
1 Inprogress 070716
1 NotCompleted 070716
2 InProgress 090916
2 completed 090916
2 null 090916
2 n/a 050816
2 Failed 100616
3 inprogress 090616
3 started 080616
3 null 070616
4 failed 101017
;

*make a cheaty code table;
Data project_codes;
  input status_code:$1. project_status:$13.;
  datalines;
7 completed
4 inprogress
5 NotCompleted
1 null
2 n/a
6 Failed
3 started
;

*figure out where projects are by slecting the max code;
proc sql;
	create table last_status_code as
	select c.id, max(d.status_code) as last_status  
	from project_status c inner join project_codes d on c.status = d.project_status
	where c.mydate &amp;lt; 090916
	group by c.id
	;
quit;

*hook them back up;
proc sql;
	create table last_status_words as
	select a.id, b.project_status  
	from last_status_code a inner join project_codes b on a.last_status = b.status_code
	;
quit;

*lay it out;
proc sql;
	create table project_standing as
	select a.id, a.status, a.mydate  
	from project_status a inner join last_status_words b on a.id = b.id and a.status = b.project_status
	;
quit;

proc print noobs;
format mydate ddmmyy10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This yields&lt;/P&gt;
&lt;PRE&gt;                                        The SAS System                                     

                                 id     status          mydate

                                 1     completed    09/09/2016
                                 2     completed    09/09/2016
                                 3     inprogress   09/06/2016
&lt;/PRE&gt;
&lt;P&gt;My apologies.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 16:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399253#M96689</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-09-27T16:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Help in Rank function -SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399298#M96702</link>
      <description>&lt;P&gt;Thank you so much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 18:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399298#M96702</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-09-27T18:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Help in Rank function -SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399304#M96704</link>
      <description>&lt;P&gt;Keep in mind - garbage in, garbage out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think if project one has two completed status entries, for example, it blows up. (You might be able to look for max code and max date to try to fix that, I don't know).&amp;nbsp; It will also blow up if you are looking for Completed and the status is completed.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2017 19:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Rank-function-SQL/m-p/399304#M96704</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-09-27T19:04:22Z</dc:date>
    </item>
  </channel>
</rss>

