<?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 Create a macro that stores the date of the last day of the previous month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-that-stores-the-date-of-the-last-day-of-the/m-p/830932#M328351</link>
    <description>&lt;P&gt;As the title says, I would like to create a macro that stores the last date of the previous month so I don't have to constantly update my code each month.&lt;/P&gt;
&lt;P&gt;My current code would only work assuming I ran the report on the 1st of the current month. However that won't always be the case. I tried using the 'B' and 'E' intnx options, but came up with an error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Current code: no B or E option*/
%let period= %sysfunc(intnx(month, %sysfunc(today()), -1), date9.)-%sysfunc(intnx(day, %sysfunc(today()), -1), date9.);

/*Log results with B and E option*/
18   %let period= %sysfunc(intnx(month, %sysfunc(today()), -1, %sysfunc('B')), date9.)-%sysfunc(intnx(month, %sysfunc(today()), -1, %sysfunc('E')),
18 ! date9.);
ERROR: Function name missing in %SYSFUNC or %QSYSFUNC macro function reference.
WARNING: Argument 4 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 29 Aug 2022 16:43:04 GMT</pubDate>
    <dc:creator>mariko5797</dc:creator>
    <dc:date>2022-08-29T16:43:04Z</dc:date>
    <item>
      <title>Create a macro that stores the date of the last day of the previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-that-stores-the-date-of-the-last-day-of-the/m-p/830932#M328351</link>
      <description>&lt;P&gt;As the title says, I would like to create a macro that stores the last date of the previous month so I don't have to constantly update my code each month.&lt;/P&gt;
&lt;P&gt;My current code would only work assuming I ran the report on the 1st of the current month. However that won't always be the case. I tried using the 'B' and 'E' intnx options, but came up with an error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Current code: no B or E option*/
%let period= %sysfunc(intnx(month, %sysfunc(today()), -1), date9.)-%sysfunc(intnx(day, %sysfunc(today()), -1), date9.);

/*Log results with B and E option*/
18   %let period= %sysfunc(intnx(month, %sysfunc(today()), -1, %sysfunc('B')), date9.)-%sysfunc(intnx(month, %sysfunc(today()), -1, %sysfunc('E')),
18 ! date9.);
ERROR: Function name missing in %SYSFUNC or %QSYSFUNC macro function reference.
WARNING: Argument 4 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Aug 2022 16:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-that-stores-the-date-of-the-last-day-of-the/m-p/830932#M328351</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2022-08-29T16:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro that stores the date of the last day of the previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-that-stores-the-date-of-the-last-day-of-the/m-p/830941#M328355</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let period= %sysfunc(intnx(month, %sysfunc(today()), -1, b), date9.)-%sysfunc(intnx(month, %sysfunc(today()), -1,e),date9.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would be wise not to format these, and not to use them in a character string such as&amp;nbsp;01JUL2022-31JUL2022&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead, you want to create a start date of the time period (unformatted) and an end data of the time period (unformatted) and then you can do something like&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if date&amp;gt;=&amp;amp;start_date and date&amp;lt;=&amp;amp;end_date then ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if date between &amp;amp;start_date and &amp;amp;end_date then ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;usually formatting is an unnecessary step that just requires more programming ... first you have to format the dates, then you have to unformat them to do the &lt;FONT face="courier new,courier"&gt;if&lt;/FONT&gt; statement ...&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 16:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-that-stores-the-date-of-the-last-day-of-the/m-p/830941#M328355</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-29T16:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro that stores the date of the last day of the previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-that-stores-the-date-of-the-last-day-of-the/m-p/830943#M328357</link>
      <description>&lt;P&gt;I don't see where you tried to give INTNX() the B or E option.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The E option seems to be what you need, the B option is the default so no need to add that.&lt;/P&gt;
&lt;PRE&gt;2941  %let period= %sysfunc(intnx(month, %sysfunc(today()), -1), date9.)
2942  -%sysfunc(intnx(month, %sysfunc(today()), -1, e), date9.);
2943  %put &amp;amp;=period;
PERIOD=01JUL2022 -31JUL2022
&lt;/PRE&gt;
&lt;P&gt;The INTNX() function does not allow options of 'B' or 'E',&amp;nbsp; Just B, E or S (or their longer versions).&lt;/P&gt;
&lt;P&gt;%SYSFUNC() does not know about (and neither do I) any SAS function named&amp;nbsp;&lt;FONT face="courier new,courier" size="5"&gt;'B' or&amp;nbsp;'E'&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 17:04:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-that-stores-the-date-of-the-last-day-of-the/m-p/830943#M328357</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-29T17:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro that stores the date of the last day of the previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-that-stores-the-date-of-the-last-day-of-the/m-p/830945#M328359</link>
      <description>I guess I should have clarified that I’m using this macro variable to just&lt;BR /&gt;change one of the report headers with ease. I’m not using it in any actual&lt;BR /&gt;calculations.&lt;BR /&gt;&lt;BR /&gt;It definitely wouldn’t kill me to manually change the dates, but it’s&lt;BR /&gt;something I easily forget, so I figured automating it a little would be&lt;BR /&gt;better.&lt;BR /&gt;</description>
      <pubDate>Mon, 29 Aug 2022 17:03:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-that-stores-the-date-of-the-last-day-of-the/m-p/830945#M328359</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2022-08-29T17:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create a macro that stores the date of the last day of the previous month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-that-stores-the-date-of-the-last-day-of-the/m-p/830947#M328360</link>
      <description>&lt;P&gt;use a DATE value to start, the intnx function with month as the interval, tell it to use the previous month and the END basis.&lt;/P&gt;
&lt;P&gt;I have no idea why you placing a dash in the middle but unless your only use is for a display in a title or such bodes ill when used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The interval alignment options 'B','E' and 'S' are not functions so should not have %sysfunc to set them and is causing your errors. Also in the macro language the quotes aren't wanted. The call for the end of the previous month would be (without format)&lt;/P&gt;
&lt;PRE&gt;%sysfunc(intnx(month, %sysfunc(today()), -1, E)) ;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Aug 2022 17:08:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-macro-that-stores-the-date-of-the-last-day-of-the/m-p/830947#M328360</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-29T17:08:09Z</dc:date>
    </item>
  </channel>
</rss>

