<?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: Writing a macro to take month end's date on 2nd of every month in table CASA_MONTH_END_31JAN23. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/858681#M339271</link>
    <description>&lt;P&gt;Just look at&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;'s code. The THEN branch will be executed on the first day of a month, the ELSE on all other days. The code works for &lt;EM&gt;all&lt;/EM&gt; days of a month.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Feb 2023 10:29:03 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-02-14T10:29:03Z</dc:date>
    <item>
      <title>Writing a macro to take month end's date on 2nd of every month in table CASA_MONTH_END_31JAN23.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/857722#M338915</link>
      <description>&lt;P&gt;Hey Guys,&lt;/P&gt;&lt;P&gt;I have tables by the name : CASA_MONTH_END_31JAN23.&lt;/P&gt;&lt;P&gt;I want to make a macro where the Date should change to the current month on the 2nd of every month.&lt;/P&gt;&lt;P&gt;e.g. If the current month is February and today is Feb 2nd then the date should be changed to 28FEB23 and table will be&amp;nbsp;CASA_MONTH_END_28FEB23. this table will be used till 1st March, then on 2nd March it should Change to March.&lt;/P&gt;&lt;P&gt;Please Help.&lt;BR /&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 11:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/857722#M338915</guid>
      <dc:creator>Discaboota</dc:creator>
      <dc:date>2023-02-08T11:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a macro to take month end's date on 2nd of every month in table CASA_MONTH_END_31JAN23.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/857735#M338923</link>
      <description>&lt;P&gt;Perhaps you mean you want a macro&amp;nbsp;&lt;EM&gt;variable&lt;/EM&gt;&amp;nbsp;and not a macro? (Macro variable and macro are different things, you should not confuse them or refer to macro variables as macros)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    if day(today())=1 then month=intnx('month',today(),-1,'e');
    else month=intnx('month',today(),0,'e');
    call symputx('month',put(month,date7.));
run;
%put &amp;amp;=month;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additional suggestion: appending month names in the format 28FEB23 to data set names are generally poor choices, as these data sets will not sort chronologically, and it requires people to correctly identify the last day of the month (which isn't hard to do, but could still be a cause of errors). Better would be to name the data sets with months in the format 2023M02, which would sort properly, and would not require people to identify the last day of the month in order to use the data set. You could then use the format YYMM7. instead of DATE7.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 12:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/857735#M338923</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-08T12:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a macro to take month end's date on 2nd of every month in table CASA_MONTH_END_31JAN23.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/857774#M338936</link>
      <description>&lt;P&gt;When you date-name files (and this includes datasets), you should always use a YMD date, like 20230131. This makes subsequent handling, like archiving or simply deleting, much easier, and the files sort chronologically on their own.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 15:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/857774#M338936</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-08T15:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a macro to take month end's date on 2nd of every month in table CASA_MONTH_END_31JAN23.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/857872#M338968</link>
      <description>&lt;P&gt;If you do want a macro, and not just a macro variable,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s logic can be translated into a function style macro, e.g.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro monthend() ;
  %local monthend ;
  %if %sysfunc(day(%sysfunc(today())))=1 %then %let monthend=%sysfunc(intnx(month,%sysfunc(today()),-1,e),date7) ;
  %else %let monthend=%sysfunc(intnx(month,%sysfunc(today()),0,e),date7) ;
  &amp;amp;monthend
%mend monthend ;

%put CASA_MONTH_END_%monthend() ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Feb 2023 20:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/857872#M338968</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-02-08T20:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a macro to take month end's date on 2nd of every month in table CASA_MONTH_END_31JAN23.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/858676#M339267</link>
      <description>&lt;P&gt;Hey, Thank you so much for the reply. I have a question, isn't this gonna change the date only on the specified date and not for the rest of the month? If I put this in my code, it is gonna change on the 1st day of the month but in my case, the 2nd day of the month. But for the 1st day, it is gonna take the current month's date. Can you please help me with it?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 08:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/858676#M339267</guid>
      <dc:creator>Discaboota</dc:creator>
      <dc:date>2023-02-14T08:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a macro to take month end's date on 2nd of every month in table CASA_MONTH_END_31JAN23.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/858677#M339268</link>
      <description>&lt;P&gt;Hey, Thank you so much for the reply. I have two questions,&lt;BR /&gt;1- Isn't this gonna change the date only on the specified date and not for the rest of the month?&lt;BR /&gt;2- If I put this in my code, it is gonna change on the 1st day of the month but in my case, the 2nd day of the month. But for the 1st day, it is gonna take the current month's date. Can you please help me with it?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 08:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/858677#M339268</guid>
      <dc:creator>Discaboota</dc:creator>
      <dc:date>2023-02-14T08:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a macro to take month end's date on 2nd of every month in table CASA_MONTH_END_31JAN23.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/858681#M339271</link>
      <description>&lt;P&gt;Just look at&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;'s code. The THEN branch will be executed on the first day of a month, the ELSE on all other days. The code works for &lt;EM&gt;all&lt;/EM&gt; days of a month.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 10:29:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/858681#M339271</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-14T10:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a macro to take month end's date on 2nd of every month in table CASA_MONTH_END_31JAN23.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/858684#M339272</link>
      <description>&lt;P&gt;Nothing is&amp;nbsp;&lt;EM&gt;changed&lt;/EM&gt; in the code. The return value is&amp;nbsp;&lt;EM&gt;set&lt;/EM&gt;, depending on the day-in-a-month of today's date. As I said in my other post, this code will also work on&amp;nbsp;&lt;EM&gt;all&lt;/EM&gt; days of a month.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 10:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/858684#M339272</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-14T10:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a macro to take month end's date on 2nd of every month in table CASA_MONTH_END_31JAN23.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/858698#M339280</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436607"&gt;@Discaboota&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hey, Thank you so much for the reply. I have a question, isn't this gonna change the date only on the specified date and not for the rest of the month?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The best way to get an answer to this question is to actually try the code and see what it does.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 11:19:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/858698#M339280</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-14T11:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Writing a macro to take month end's date on 2nd of every month in table CASA_MONTH_END_31JAN23.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/858713#M339284</link>
      <description>&lt;P&gt;On the first day of the month, it returns the last day of the prior month.&lt;/P&gt;
&lt;P&gt;On every other day of the month, it returns the last day of the current month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use the macro approach, you can make the code testable by adding a parameter for the value of today, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro monthend(today=%sysfunc(today())) ;
  %local monthend ;
  %if %sysfunc(day(&amp;amp;today))=1 %then %let monthend=%sysfunc(intnx(month,&amp;amp;today,-1,e),date7) ;
  %else %let monthend=%sysfunc(intnx(month,&amp;amp;today,0,e),date7) ;
  &amp;amp;monthend
%mend monthend ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then test dates like as below:&lt;/P&gt;
&lt;PRE&gt;9    %put CASA_MONTH_END_%monthend() ;
CASA_MONTH_END_28FEB23

10   %put CASA_MONTH_END_%monthend(today="01Jan2023"d) ;
CASA_MONTH_END_31DEC22

11   %put CASA_MONTH_END_%monthend(today="02Jan2023"d) ;
CASA_MONTH_END_31JAN23

12   %put CASA_MONTH_END_%monthend(today="03Jan2023"d) ;
CASA_MONTH_END_31JAN23

13   %put CASA_MONTH_END_%monthend(today="31Jan2023"d) ;
CASA_MONTH_END_31JAN23

14   %put CASA_MONTH_END_%monthend(today="01Feb2023"d) ;
CASA_MONTH_END_31JAN23

15   %put CASA_MONTH_END_%monthend(today="02Feb2023"d) ;
CASA_MONTH_END_28FEB23
&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Feb 2023 13:15:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Writing-a-macro-to-take-month-end-s-date-on-2nd-of-every-month/m-p/858713#M339284</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-02-14T13:15:06Z</dc:date>
    </item>
  </channel>
</rss>

