<?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: How to change over partition and with table as statement in a SQL code in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/933915#M44910</link>
    <description>&lt;P&gt;It would help a lot if you explained what the code you shared is supposed to be doing.&lt;/P&gt;
&lt;P&gt;But the simple answer is to NOT use&amp;nbsp;SQL.&amp;nbsp; Just write it in plain old SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To replicate a WITH clause either make the dataset before hand. Or define a view that will make it on demand.&amp;nbsp; But your current WITH clause does not appear to have any FROM clause, so it is not clear to me how that is valid SQL.&amp;nbsp; If you just want to make constant values then there is no need to make a dataset for that.&lt;/P&gt;
&lt;P&gt;To manipulate date values use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/v_052/lefunctionsref/p10v3sa3i4kfxfn1sovhi5xzxh8n.htm" target="_self"&gt;INTNX() function&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Looks like you might be wanting to do something like this.&amp;nbsp; But it is not clear why you want one of the value to be a DATE value (number of days) and the other to be a DATETIME value (number of seconds).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PIT_day = intnx('month',date(),-2,'e');
AUTH_DT = intnx('dtmonth',datetime(),-3,'b')+'20:30:00't ;
format pit_day date9. auth_dt datetime19.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To number observations use a &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1dfiqj146yi2cn1maeju9wo7ijs.htm" target="_self"&gt;SUM statement&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;It looks like you are trying number the observations within BY groups.&amp;nbsp; Not clear why you want the new variable as the first variable in the dataset but this should do it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
   NO + 1;
   set table_1;
   by MAIN_INSRR_CO_NBR pol_typ_cd pol_nbr descending TRM_NBR descending TRM_VER_NBR;
   if first.pol_nbr then NO=1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that if the data is not already sorted then SAS will fail this step so you might need to first run PROC SORT with the same BY statement to get the data in the needed order.&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jun 2024 15:36:18 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-06-27T15:36:18Z</dc:date>
    <item>
      <title>How to change over partition and with table as statement in a SQL code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/933897#M44906</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I dont think that SAS recognize the SQL statement with table as neither over partition.&amp;nbsp; Which changes do I need to do to work with SAS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;with 

dates as (
   select  date_trunc('MONTH', current_date)-1 as  PIT_day,
   to_timestamp(to_char(date_trunc('MONTH', current_date)-3,'YYYY-MM-DD') || ' 20:30:00','YYYY-MM-DD HH24:MI:SS')  as AUTH_DT
)

&lt;/CODE&gt;&lt;/PRE&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;</description>
      <pubDate>Thu, 27 Jun 2024 12:51:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/933897#M44906</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-06-27T12:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to change over partition and with table as statement in a SQL code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/933898#M44907</link>
      <description>&lt;P&gt;I don't understand the question, your description is far too brief.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show us the complete PROC SQL for this problem, and provide sample data and desired output.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2024 12:54:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/933898#M44907</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-06-27T12:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to change over partition and with table as statement in a SQL code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/933900#M44908</link>
      <description>&lt;P&gt;That's correct, SAS doesn't support windowing functions (which has a SAS ballot entry for btw, feel free to vore &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://communities.sas.com/t5/SASware-Ballot-Ideas/Add-window-functions-in-SAS-SQL/idi-p/462556#comments" target="_blank"&gt;Add window functions in SAS SQL - SAS Support Communities&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data resides in adatabase that support these functions, you could use explict SQL pass.through.&lt;/P&gt;
&lt;P&gt;If you need to use SAS syntax still, please provide a &lt;EM&gt;have&lt;/EM&gt; example data set (using datalines) and a &lt;EM&gt;want&lt;/EM&gt; output so we don't have dry interpret your SQL &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2024 13:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/933900#M44908</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2024-06-27T13:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to change over partition and with table as statement in a SQL code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/933902#M44909</link>
      <description>&lt;P&gt;The second one might look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&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;</description>
      <pubDate>Thu, 27 Jun 2024 13:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/933902#M44909</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-06-27T13:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to change over partition and with table as statement in a SQL code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/933915#M44910</link>
      <description>&lt;P&gt;It would help a lot if you explained what the code you shared is supposed to be doing.&lt;/P&gt;
&lt;P&gt;But the simple answer is to NOT use&amp;nbsp;SQL.&amp;nbsp; Just write it in plain old SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To replicate a WITH clause either make the dataset before hand. Or define a view that will make it on demand.&amp;nbsp; But your current WITH clause does not appear to have any FROM clause, so it is not clear to me how that is valid SQL.&amp;nbsp; If you just want to make constant values then there is no need to make a dataset for that.&lt;/P&gt;
&lt;P&gt;To manipulate date values use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/v_052/lefunctionsref/p10v3sa3i4kfxfn1sovhi5xzxh8n.htm" target="_self"&gt;INTNX() function&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Looks like you might be wanting to do something like this.&amp;nbsp; But it is not clear why you want one of the value to be a DATE value (number of days) and the other to be a DATETIME value (number of seconds).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PIT_day = intnx('month',date(),-2,'e');
AUTH_DT = intnx('dtmonth',datetime(),-3,'b')+'20:30:00't ;
format pit_day date9. auth_dt datetime19.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To number observations use a &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1dfiqj146yi2cn1maeju9wo7ijs.htm" target="_self"&gt;SUM statement&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;It looks like you are trying number the observations within BY groups.&amp;nbsp; Not clear why you want the new variable as the first variable in the dataset but this should do it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
   NO + 1;
   set table_1;
   by MAIN_INSRR_CO_NBR pol_typ_cd pol_nbr descending TRM_NBR descending TRM_VER_NBR;
   if first.pol_nbr then NO=1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that if the data is not already sorted then SAS will fail this step so you might need to first run PROC SORT with the same BY statement to get the data in the needed order.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2024 15:36:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/933915#M44910</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-27T15:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to change over partition and with table as statement in a SQL code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/934003#M44911</link>
      <description>&lt;P&gt;If you really like to use SQL ,you could try this one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
proc sql number;
ods output sql_results=temp;
select * from sashelp.class order by sex;



create table want as
select *,row-min(row)+1 as seq from temp group by sex order by row;
quit;
ods select all;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jun 2024 02:28:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/934003#M44911</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-06-28T02:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to change over partition and with table as statement in a SQL code</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/936165#M45027</link>
      <description>&lt;P&gt;Good morning,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the SAS script equivalent to partition over.&lt;/P&gt;
&lt;P&gt;How do we add the instructions order by TRM_NBR desc, TRM_VER_NBR desc.&amp;nbsp; Do we add it into the by statement or is it better to do a proc sort&amp;nbsp; by MAIN_INSRR_CO_NBR, pol_typ_cd,pol_nbr order by TRM_NBR desc, TRM_VER_NBR desc.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2024 13:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-change-over-partition-and-with-table-as-statement-in-a/m-p/936165#M45027</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2024-07-18T13:17:20Z</dc:date>
    </item>
  </channel>
</rss>

