<?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 Issue with intnx function within a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-intnx-function-within-a-macro/m-p/639592#M190305</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having some issues getting the following code to execute as intended:&lt;/P&gt;&lt;P&gt;%macro ck (start=, end=);&lt;BR /&gt;%let start=%sysfunc(inputn(&amp;amp;start.,YYMMN6.));&lt;BR /&gt;%let end=%sysfunc(inputn(&amp;amp;end.,YYMMN6.));&lt;BR /&gt;%let dif=%sysfunc(intck(month,&amp;amp;start.,&amp;amp;end.));&lt;BR /&gt;%do i=0 %to &amp;amp;dif.;&lt;BR /&gt;%let date=%sysfunc(intnx(month,&amp;amp;start.,&amp;amp;i.,b),YYMMN6.);&lt;BR /&gt;%put &amp;amp;date.;&lt;BR /&gt;%let date2=%sysfunc(intnx(month,&amp;amp;date.,1));&lt;BR /&gt;%put &amp;amp;date2.;&lt;BR /&gt;%end;&lt;BR /&gt;%mend ck;&lt;/P&gt;&lt;P&gt;%ck(start=201701,end=201802);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The macro variable &lt;EM&gt;date&lt;/EM&gt; is executing the way I'd like it to, looping through 201701 to 201802, but &lt;EM&gt;date2&lt;/EM&gt; is not.&amp;nbsp; I am trying to have date2 be one month later than date.&amp;nbsp; My log shows the following:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ItsAProccess_0-1586815439800.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/38273i012B43A8E06E1253/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ItsAProccess_0-1586815439800.png" alt="ItsAProccess_0-1586815439800.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why does SAS think that 201701 + 1 month is 201705? As the loop progresses the values for date2 get further out of expected range.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd appreciate any feedback and help, thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Apr 2020 22:05:47 GMT</pubDate>
    <dc:creator>ItsAProccess</dc:creator>
    <dc:date>2020-04-13T22:05:47Z</dc:date>
    <item>
      <title>Issue with intnx function within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-intnx-function-within-a-macro/m-p/639592#M190305</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having some issues getting the following code to execute as intended:&lt;/P&gt;&lt;P&gt;%macro ck (start=, end=);&lt;BR /&gt;%let start=%sysfunc(inputn(&amp;amp;start.,YYMMN6.));&lt;BR /&gt;%let end=%sysfunc(inputn(&amp;amp;end.,YYMMN6.));&lt;BR /&gt;%let dif=%sysfunc(intck(month,&amp;amp;start.,&amp;amp;end.));&lt;BR /&gt;%do i=0 %to &amp;amp;dif.;&lt;BR /&gt;%let date=%sysfunc(intnx(month,&amp;amp;start.,&amp;amp;i.,b),YYMMN6.);&lt;BR /&gt;%put &amp;amp;date.;&lt;BR /&gt;%let date2=%sysfunc(intnx(month,&amp;amp;date.,1));&lt;BR /&gt;%put &amp;amp;date2.;&lt;BR /&gt;%end;&lt;BR /&gt;%mend ck;&lt;/P&gt;&lt;P&gt;%ck(start=201701,end=201802);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The macro variable &lt;EM&gt;date&lt;/EM&gt; is executing the way I'd like it to, looping through 201701 to 201802, but &lt;EM&gt;date2&lt;/EM&gt; is not.&amp;nbsp; I am trying to have date2 be one month later than date.&amp;nbsp; My log shows the following:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ItsAProccess_0-1586815439800.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/38273i012B43A8E06E1253/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ItsAProccess_0-1586815439800.png" alt="ItsAProccess_0-1586815439800.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why does SAS think that 201701 + 1 month is 201705? As the loop progresses the values for date2 get further out of expected range.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd appreciate any feedback and help, thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Apr 2020 22:05:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-intnx-function-within-a-macro/m-p/639592#M190305</guid>
      <dc:creator>ItsAProccess</dc:creator>
      <dc:date>2020-04-13T22:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with intnx function within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-intnx-function-within-a-macro/m-p/639593#M190306</link>
      <description>&lt;P&gt;Important rule: do NOT format macro variables for use in arithmetic or logical operations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let date=%sysfunc(intnx(month,&amp;amp;start.,&amp;amp;i.,b));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Mon, 13 Apr 2020 22:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-intnx-function-within-a-macro/m-p/639593#M190306</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-13T22:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with intnx function within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-intnx-function-within-a-macro/m-p/639597#M190310</link>
      <description>&lt;P&gt;It is because it is the first day of the next month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;201,701 is the 28th of March and 201,705 is the first of April.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try formatting those numbers as dates and you will see that.&lt;/P&gt;
&lt;PRE&gt;1692  %macro ck (start=, end=);
1693  %let start=%sysfunc(inputn(&amp;amp;start.,YYMMN6.));
1694  %let end=%sysfunc(inputn(&amp;amp;end.,YYMMN6.));
1695  %let dif=%sysfunc(intck(month,&amp;amp;start.,&amp;amp;end.));
1696  %do i=0 %to &amp;amp;dif.;
1697  %let date=%sysfunc(intnx(month,&amp;amp;start.,&amp;amp;i.,b),YYMMN6.);
1698  %let date2=%sysfunc(intnx(month,&amp;amp;date.,1));
1699  %put &amp;amp;=date %sysfunc(putn(&amp;amp;date,date9)) &amp;amp;=date2 %sysfunc(putn(&amp;amp;date2,date9));
1700  %end;
1701  %mend ck;
1702
1703  %ck(start=201701,end=201702);
DATE=201701 28MAR2512 DATE2=201705 01APR2512
DATE=201702 29MAR2512 DATE2=201705 01APR2512
&lt;/PRE&gt;
&lt;P&gt;I assume you wanted to do this instead?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ck (start=, end=);
%let start=%sysfunc(inputn(&amp;amp;start.,YYMMN6.));
%let end=%sysfunc(inputn(&amp;amp;end.,YYMMN6.));
%let dif=%sysfunc(intck(month,&amp;amp;start.,&amp;amp;end.));
%do i=0 %to &amp;amp;dif.;
%let date=%sysfunc(intnx(month,&amp;amp;start.,&amp;amp;i.,b),YYMMN6.);
%let date2=%sysfunc(intnx(month,&amp;amp;start.,&amp;amp;i+1),YYMMN6.);
%put &amp;amp;=date &amp;amp;=date2 ;
%end;
%mend ck;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;1727  %ck(start=201701,end=201702);
DATE=201701 DATE2=201702
DATE=201702 DATE2=201703
&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Apr 2020 22:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-intnx-function-within-a-macro/m-p/639597#M190310</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-13T22:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with intnx function within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-intnx-function-within-a-macro/m-p/639611#M190314</link>
      <description>&lt;P&gt;This is not a macro or intnx issue.&lt;/P&gt;
&lt;P&gt;Your variable &amp;amp;date contains a formatted date.&lt;/P&gt;
&lt;P&gt;intnx() needs the raw value, a SAS date, as its input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 00:15:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-intnx-function-within-a-macro/m-p/639611#M190314</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-04-14T00:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with intnx function within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issue-with-intnx-function-within-a-macro/m-p/639614#M190317</link>
      <description>Thanks!!</description>
      <pubDate>Tue, 14 Apr 2020 00:26:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issue-with-intnx-function-within-a-macro/m-p/639614#M190317</guid>
      <dc:creator>ItsAProccess</dc:creator>
      <dc:date>2020-04-14T00:26:47Z</dc:date>
    </item>
  </channel>
</rss>

