<?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: Help working with dates in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Help-working-with-dates/m-p/572351#M12303</link>
    <description>&lt;P&gt;I think you are asking if the max date is in the current month?&lt;/P&gt;
&lt;P&gt;You might want to use the INTNX() function to adjust the dates to the beginning (or end) of a month.&lt;/P&gt;
&lt;P&gt;So perhaps&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx('month',max_dt,0) = intnx('month',today(),0)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jul 2019 13:38:49 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-07-10T13:38:49Z</dc:date>
    <item>
      <title>Help working with dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-working-with-dates/m-p/571988#M12265</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could someone please help me with this code, I dont have much experience with date&amp;nbsp; and macros.&lt;/P&gt;&lt;P&gt;I need to create a dataset based on a date condition, I mean look into table A and see if the month of the maximum date in this table is equal to current month or previous month, if yes&amp;nbsp; then create a table with the max date found in table A.&lt;/P&gt;&lt;P&gt;Example Table A&lt;/P&gt;&lt;P&gt;Month_end_dt&amp;nbsp; &amp;nbsp;ID&lt;/P&gt;&lt;P&gt;30/04/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;30/05/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;30/06/ 2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So as we are on July/19&amp;nbsp; and max Month_end_date is 30/06/2019 on table A then&amp;nbsp; the trigger is fine ( current month less 1), so start the process to create a table B with the max Month_end_date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried this but is not working properly:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint ;&lt;BR /&gt;connect to teradata&lt;BR /&gt;(user=&amp;amp;teradata_user. password=&amp;amp;teradata_pwd. server = 'edwprod' database = 'nuc_pl_user_view');&lt;BR /&gt;Create table work.statuspayg as&lt;BR /&gt;(&lt;BR /&gt;select max_month&lt;BR /&gt;&lt;BR /&gt;from (select max(month((month_end_dt)) as max_month from table A)&lt;BR /&gt;)&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;BR /&gt;%macro test;&lt;BR /&gt;%if max_month&amp;lt;= current_month or current_month - 1 %then %do;&lt;BR /&gt;data jorquec.STATUSPAYG_final;&lt;BR /&gt;set work.statuspayg;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 10:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-working-with-dates/m-p/571988#M12265</guid>
      <dc:creator>jorquec</dc:creator>
      <dc:date>2019-07-09T10:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Help working with dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-working-with-dates/m-p/572132#M12279</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270435"&gt;@jorquec&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could someone please help me with this code, I dont have much experience with date&amp;nbsp; and macros.&lt;/P&gt;
&lt;P&gt;I need to create a dataset based on a date condition, I mean look into table A and see if the month of the maximum date in this table is equal to current month or previous month, if yes&amp;nbsp; then create a table with the max date found in table A.&lt;/P&gt;
&lt;P&gt;Example Table A&lt;/P&gt;
&lt;P&gt;Month_end_dt&amp;nbsp; &amp;nbsp;ID&lt;/P&gt;
&lt;P&gt;30/04/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;30/05/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;
&lt;P&gt;30/06/ 2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So as we are on July/19&amp;nbsp; and max Month_end_date is 30/06/2019 on table A then&amp;nbsp; the trigger is fine ( current month less 1), so start the process to create a table B with the max Month_end_date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried this but is not working properly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql noprint ;&lt;BR /&gt;connect to teradata&lt;BR /&gt;(user=&amp;amp;teradata_user. password=&amp;amp;teradata_pwd. server = 'edwprod' database = 'nuc_pl_user_view');&lt;BR /&gt;Create table work.statuspayg as&lt;BR /&gt;(&lt;BR /&gt;select max_month&lt;BR /&gt;&lt;BR /&gt;from (select max(month((month_end_dt)) as max_month from table A)&lt;BR /&gt;)&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;quit;&lt;BR /&gt;%macro test;&lt;BR /&gt;%if max_month&amp;lt;= current_month or current_month - 1 %then %do;&lt;BR /&gt;data jorquec.STATUSPAYG_final;&lt;BR /&gt;set work.statuspayg;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can you show an example that works without any macro variables or macro code?&lt;/P&gt;
&lt;P&gt;If we see that then we can suggest changes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a minimum your macro test does not have any value for the "max_month" or "current_month". It is comparing literal text and max_month will always be greater than current_month as "m" comes after "c" (is greater than) when comparing text values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that it is a &lt;STRONG&gt;very good idea&lt;/STRONG&gt; to actually pass parameters to a macro and not have values just "appear" in the middle of code as it becomes very hard to determine where the value may have originated.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 15:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-working-with-dates/m-p/572132#M12279</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-09T15:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Help working with dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-working-with-dates/m-p/572310#M12293</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I have tried this below and it works, the problem is that Today is not a good reference for my process. I would like something that check if max month_end_date on Table A is equal to current month or previous month than create a table B.&lt;/P&gt;&lt;P&gt;I don't have any idea how to create this logical. Any help will be great.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql noprint ;&lt;BR /&gt;connect to teradata&lt;BR /&gt;(user=&amp;amp;teradata_user. password=&amp;amp;teradata_pwd. server = 'edwprod' database = 'nuc_pl_user_view');&lt;BR /&gt;Create table STATUSPAYG as(&lt;BR /&gt;select max_dt = today()&lt;BR /&gt;into :today trimmed&lt;BR /&gt;from (select max(month_end_dt) as max_dt from table A)&lt;BR /&gt;)&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;BR /&gt;%macro test;&lt;BR /&gt;%if &amp;amp;today %then %do;&lt;BR /&gt;data tableB_final;&lt;BR /&gt;set STATUSPAYG;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 10:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-working-with-dates/m-p/572310#M12293</guid>
      <dc:creator>jorquec</dc:creator>
      <dc:date>2019-07-10T10:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Help working with dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-working-with-dates/m-p/572351#M12303</link>
      <description>&lt;P&gt;I think you are asking if the max date is in the current month?&lt;/P&gt;
&lt;P&gt;You might want to use the INTNX() function to adjust the dates to the beginning (or end) of a month.&lt;/P&gt;
&lt;P&gt;So perhaps&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx('month',max_dt,0) = intnx('month',today(),0)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 13:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-working-with-dates/m-p/572351#M12303</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-10T13:38:49Z</dc:date>
    </item>
  </channel>
</rss>

