<?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: Oracle row number() in sas with proc rank in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Oracle-row-number-in-sas-with-proc-rank/m-p/832717#M329153</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24745"&gt;@Rakeon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I need to convert this Oracle Code in SAS :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;row_number() over (partition by Var1, Var2, Var3 &lt;BR /&gt;                       order by Var 4, Var5, Var6) &lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I believe below should return the same result.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=want;
  by Var1 Var2 Var3 Var4 Var5 Var6;
run;
  
data want;
  set want;
  by Var1 Var2 Var3;
  if first.var3 then row_num=1;
  else row_num+1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;NB: In your subject line you mention Proc Rank BUT in the Oracle SQL code you're using row_number()&lt;/P&gt;
&lt;P&gt;If you need anything that can deal with ties (multiple rows with identical values for variables var1 to var6) then you would need to use Oracle functions RANK() or RANK_DENSE() ...and in doing so the SAS code would also need to look a bit differently.&lt;/P&gt;</description>
    <pubDate>Sun, 11 Sep 2022 10:23:51 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2022-09-11T10:23:51Z</dc:date>
    <item>
      <title>Oracle row number() in sas with proc rank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Oracle-row-number-in-sas-with-proc-rank/m-p/832522#M329061</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I need to convert this Oracle Code in SAS :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;row_number() over (partition by Var1, Var2, Var3 &lt;BR /&gt;                       order by Var 4, Var5, Var6) &lt;/PRE&gt;
&lt;P&gt;I'm trying with proc rank, but it requires just one variable in rank parameter.&lt;BR /&gt;I would like to know if is there any chance to implement it with proc rank.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2022 15:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Oracle-row-number-in-sas-with-proc-rank/m-p/832522#M329061</guid>
      <dc:creator>Rakeon</dc:creator>
      <dc:date>2022-09-09T15:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Oracle row number() in sas with proc rank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Oracle-row-number-in-sas-with-proc-rank/m-p/832523#M329062</link>
      <description>&lt;P&gt;No, but data step + proc sort would probably work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure this is quite right, but the idea is there&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by var1 var2 var3;
if first.var then count=0;
else count+1;
run;

proc sort data=want;
by var4 var5 var6;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Sep 2022 15:55:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Oracle-row-number-in-sas-with-proc-rank/m-p/832523#M329062</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-09T15:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: Oracle row number() in sas with proc rank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Oracle-row-number-in-sas-with-proc-rank/m-p/832717#M329153</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24745"&gt;@Rakeon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I need to convert this Oracle Code in SAS :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;row_number() over (partition by Var1, Var2, Var3 &lt;BR /&gt;                       order by Var 4, Var5, Var6) &lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I believe below should return the same result.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=want;
  by Var1 Var2 Var3 Var4 Var5 Var6;
run;
  
data want;
  set want;
  by Var1 Var2 Var3;
  if first.var3 then row_num=1;
  else row_num+1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;NB: In your subject line you mention Proc Rank BUT in the Oracle SQL code you're using row_number()&lt;/P&gt;
&lt;P&gt;If you need anything that can deal with ties (multiple rows with identical values for variables var1 to var6) then you would need to use Oracle functions RANK() or RANK_DENSE() ...and in doing so the SAS code would also need to look a bit differently.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Sep 2022 10:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Oracle-row-number-in-sas-with-proc-rank/m-p/832717#M329153</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-09-11T10:23:51Z</dc:date>
    </item>
  </channel>
</rss>

