<?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 convert over partition into sas code in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/convert-over-partition-into-sas-code/m-p/936180#M45028</link>
    <description>&lt;P&gt;Here's the sql code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select row_number() over (partition by MAIN_INSRR_CO_NBR, pol_typ_cd,pol_nbr order by TRM_NBR desc, TRM_VER_NBR desc) as NO, 
 aa.*
 from  table_1 aa&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In a previous question, it was provided the anwser below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;data want;
set table1;
by MAIN_INSRR_CO_NBR pol_typ_cd pol_nbr;
if first.pol_nbr
then no = 1;
else no + 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But how do we deal with the&amp;nbsp;&lt;CODE class=" language-sas"&gt;order by TRM_NBR desc, TRM_VER_NBR desc?&lt;BR /&gt;How do we include it into the dataset want ?&lt;BR /&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jul 2024 13:59:24 GMT</pubDate>
    <dc:creator>alepage</dc:creator>
    <dc:date>2024-07-18T13:59:24Z</dc:date>
    <item>
      <title>convert over partition into sas code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/convert-over-partition-into-sas-code/m-p/936180#M45028</link>
      <description>&lt;P&gt;Here's the sql code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select row_number() over (partition by MAIN_INSRR_CO_NBR, pol_typ_cd,pol_nbr order by TRM_NBR desc, TRM_VER_NBR desc) as NO, 
 aa.*
 from  table_1 aa&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In a previous question, it was provided the anwser below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;data want;
set table1;
by MAIN_INSRR_CO_NBR pol_typ_cd pol_nbr;
if first.pol_nbr
then no = 1;
else no + 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But how do we deal with the&amp;nbsp;&lt;CODE class=" language-sas"&gt;order by TRM_NBR desc, TRM_VER_NBR desc?&lt;BR /&gt;How do we include it into the dataset want ?&lt;BR /&gt;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2024 13:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/convert-over-partition-into-sas-code/m-p/936180#M45028</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-07-18T13:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: convert over partition into sas code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/convert-over-partition-into-sas-code/m-p/936195#M45030</link>
      <description>&lt;P&gt;Read how to specify a &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p0yeyftk8ftuckn1o5qzy53284gz.htm" target="_self"&gt;BY statement&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2024 15:00:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/convert-over-partition-into-sas-code/m-p/936195#M45030</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-18T15:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: convert over partition into sas code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/convert-over-partition-into-sas-code/m-p/936205#M45032</link>
      <description>&lt;P&gt;Hello Tom, Thank you for the link to a by statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question was how to convert the over partion sql statement into a sas code to obtain the same result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;select row_number() over (partition by MAIN_INSRR_CO_NBR, pol_typ_cd,pol_nbr order by TRM_NBR desc, TRM_VER_NBR desc) as NO, 
 aa.*
 from  table_1 aa&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;In this over partion statement we have a by main_insrr_co_nbr, pol_typ_nbr order by trm_nbr des, trm_ver_nbr des.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the example provided, we have&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;data want;
set table1;
by MAIN_INSRR_CO_NBR pol_typ_cd pol_nbr;
if first.pol_nbr
then no = 1;
else no + 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;as you can see, the portion of the sql script, i.e., the order by trm_nbr des, trm_ver_nbr des is not included into the proposed SAS code.&lt;/P&gt;
&lt;P&gt;Thank you very much for the conversion example.&amp;nbsp; But what do we do with the order by statement (sql) into the SAS code.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=table_1;&lt;BR /&gt;by MAIN_INSRR_CO_NBR pol_typ_cd pol_nbr descending TRM_NBR descending TRM_VER_NBR;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;data sort;&lt;BR /&gt;set table_1;&lt;BR /&gt;by MAIN_INSRR_CO_NBR pol_typ_cd pol_nbr;&lt;BR /&gt;if first.pol_nbr&lt;BR /&gt;then no = 1;&lt;BR /&gt;else no + 1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data sort;&lt;BR /&gt;set table_1;&lt;BR /&gt;by MAIN_INSRR_CO_NBR pol_typ_cd pol_nbr descending TRM_NBR descending TRM_VER_NBR;&lt;BR /&gt;if first.pol_nbr&lt;BR /&gt;then no = 1;&lt;BR /&gt;else no + 1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand the over partition by ..... order by statement into the sql script. Therefore, I dont know how to convert it to SAS code.&amp;nbsp; It is why I asking for help&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2024 15:29:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/convert-over-partition-into-sas-code/m-p/936205#M45032</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-07-18T15:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: convert over partition into sas code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/convert-over-partition-into-sas-code/m-p/936214#M45033</link>
      <description>&lt;P&gt;So find a source for what PARTITION BY does. Here is one &lt;A href="https://www.sqlshack.com/sql-partition-by-clause-overview/" target="_blank" rel="noopener"&gt;https://www.sqlshack.com/sql-partition-by-clause-overview/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;partition by MAIN_INSRR_CO_NBR, pol_typ_cd,pol_nbr
  order by TRM_NBR desc, TRM_VER_NBR desc&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically you are saying to treat observations with the same values of&amp;nbsp;MAIN_INSRR_CO_NBR, pol_typ_cd and pol_nbr as separate subsets (partitions).&amp;nbsp; And within each of those subsets to sort the observations using descending TRM_NBR and descending TRM_VER_NBR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your BY statement is going to use ALL of those variables.&amp;nbsp; For the first 3 it does not really matter to SQL whether they are ordered ascending or descending.&amp;nbsp; But for the last two it does.&amp;nbsp; Otherwise you will number the observations in the opposite order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So use this BY statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by MAIN_INSRR_CO_NBR pol_typ_cd pol_nbr
   descending TRM_NBR descending TRM_VER_NBR
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you want to restart the numbering when FIRST.POL_NBR is TRUE.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2024 15:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/convert-over-partition-into-sas-code/m-p/936214#M45033</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-18T15:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: convert over partition into sas code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/convert-over-partition-into-sas-code/m-p/936220#M45035</link>
      <description>It is the first time for me that someone take the time to explain me what does over partion.  It is clear for me now. Thank you very much.</description>
      <pubDate>Thu, 18 Jul 2024 16:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/convert-over-partition-into-sas-code/m-p/936220#M45035</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-07-18T16:12:03Z</dc:date>
    </item>
  </channel>
</rss>

