<?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 understanding MACRO functionality in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329697#M73821</link>
    <description>&lt;P&gt;Simplify, simplify, simplify:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro date_loop(start,end);
	%do i = 0 %to %sysfunc(intck(month, "&amp;amp;start"d, "&amp;amp;end"d));
		%let date = %sysfunc(intnx(month,"&amp;amp;start"d, &amp;amp;i, b), date9.);
		%put &amp;amp;date;
	%end;
%mend date_loop;

%date_loop(01jul2015, 01feb2016);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 03 Feb 2017 06:25:01 GMT</pubDate>
    <dc:creator>LaurieF</dc:creator>
    <dc:date>2017-02-03T06:25:01Z</dc:date>
    <item>
      <title>help understanding MACRO functionality</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329546#M73744</link>
      <description>&lt;P&gt;The&amp;nbsp;first macro below I got from SAS&amp;nbsp;website.&amp;nbsp; I want to eliminate the %let start=, %let end=,&amp;nbsp;and %let dif=, statements and just have the INTCK calculation done in the "%do i = 0 %to" line.&amp;nbsp; If I make substitutions one at a time, the code works fine up until&amp;nbsp;I attempt to substitute&amp;nbsp;"%let start ="&amp;nbsp;piece.&amp;nbsp; If you try to run the code below, the first 3 will work but the last one will not.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help me understand why the last code will not work.&amp;nbsp; Thanks in advance.&lt;/P&gt;
&lt;P&gt;* THIS IS THE ORIGINAL FILE FROM THE SUPPORT.SAS WEBSITE;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro date_loop(start,end);
	%let start=%sysfunc(inputn(&amp;amp;start,anydtdte9.));
	%let end=%sysfunc(inputn(&amp;amp;end,anydtdte9.));
	%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),date9.);
		%put &amp;amp;date;
	%end;
%mend date_loop;

%date_loop(01jul2015,01feb2016);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;* THIS DOES THE &amp;amp;dif CALCULATION IN THE DO LOOP;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro date_loop(start,end);
	%let start=%sysfunc(inputn(&amp;amp;start,anydtdte9.));
	%let end=%sysfunc(inputn(&amp;amp;end,anydtdte9.));

	%do i=0 %to %sysfunc(intck(month,&amp;amp;start,&amp;amp;end));
		%let date=%sysfunc(intnx(month,&amp;amp;start,&amp;amp;i,b),date9.);
		%put &amp;amp;date;
	%end;
%mend date_loop;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;* THIS SUBSTITUTES THE "%let end=" LINE INTO THE 3RD ARGUMENT OF THE INTCK FUNCTION;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro date_loop(start,end);
	%let start=%sysfunc(inputn(&amp;amp;start,anydtdte9.));

	%do i=0 %to %sysfunc(intck(month,&amp;amp;start,%sysfunc(inputn(&amp;amp;end,anydtdte9.))));
		%let date=%sysfunc(intnx(month,&amp;amp;start,&amp;amp;i,b),date9.);
		%put &amp;amp;date;
	%end;
%mend date_loop;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;* THIS SUBSTITUTES THE "%let start=" LINE INTO THE 2RD ARGUMENT OF THE INTCK FUNCTION;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro date_loop(start,end);
	%do i=0 %to %sysfunc(intck(month,%sysfunc(inputn(&amp;amp;start,anydtdte9.)),%sysfunc(inputn(&amp;amp;end,anydtdte9.))));
		%let date=%sysfunc(intnx(month,&amp;amp;start,&amp;amp;i,b),date9.);
		%put &amp;amp;date;
	%end;
%mend date_loop;&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;</description>
      <pubDate>Thu, 02 Feb 2017 20:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329546#M73744</guid>
      <dc:creator>GeorgeBonanza</dc:creator>
      <dc:date>2017-02-02T20:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: help understanding MACRO functionality</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329567#M73750</link>
      <description>&lt;P&gt;I haven'ttest it but it seems to me that you should not enter %sysfunc within %sysfunc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example - instead line&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" color="#0000ff"&gt;%to&lt;/FONT&gt; &lt;FONT face="Courier New" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;(intck(month,&amp;amp;start,&lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;(inputn(&amp;amp;end,&lt;/FONT&gt;&lt;FONT face="Courier New" color="#008080"&gt;anydtdte9.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;))));&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="3"&gt;&lt;FONT face="Courier New"&gt;it should be:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#008080"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" color="#0000ff"&gt;%to&lt;/FONT&gt; &lt;FONT face="Courier New" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;(intck(month,&amp;amp;start,&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;inputn(&amp;amp;end,&lt;/FONT&gt;&lt;FONT face="Courier New" color="#008080"&gt;anydtdte9.&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;)));&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 20:30:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329567#M73750</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-02-02T20:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: help understanding MACRO functionality</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329574#M73753</link>
      <description>&lt;P&gt;But - but - in your &lt;EM&gt;intnx&lt;/EM&gt; function in the&amp;nbsp;&lt;EM&gt;%let&lt;/EM&gt; within the&amp;nbsp;&lt;EM&gt;%do&lt;/EM&gt; loop - you're passing in&amp;nbsp;&lt;EM&gt;01jul2015&lt;/EM&gt;, not&amp;nbsp;&lt;EM&gt;20270&lt;/EM&gt;. You have to convert it somewhere!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have never, ever, made this mistake mistake. Oh, no, no, no, no, no…&amp;nbsp;&lt;img id="smileyvery-happy" class="emoticon emoticon-smileyvery-happy" src="https://communities.sas.com/i/smilies/16x16_smiley-very-happy.png" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, you can convert dates like that on the fly with&amp;nbsp;&lt;EM&gt;%sysevalf&lt;/EM&gt;, funnily enough.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;%let date=%sysfunc(intnx(month, %sysevalf("&amp;amp;start"d) ,&amp;amp;i,b),date9.);&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;or even simply&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date=%sysfunc(intnx(month, "&amp;amp;start"d ,&amp;amp;i,b),date9.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 20:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329574#M73753</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-02T20:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: help understanding MACRO functionality</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329576#M73754</link>
      <description>No, multiple %sysfuncs are fine. It can make it hard to read, but it does work very well.</description>
      <pubDate>Thu, 02 Feb 2017 20:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329576#M73754</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-02T20:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: help understanding MACRO functionality</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329581#M73757</link>
      <description>&lt;P&gt;I thought it was erroring out in the do loop.&amp;nbsp; you are correct, that was a dumb error, glad you never made a similar mistake.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 20:58:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329581#M73757</guid>
      <dc:creator>GeorgeBonanza</dc:creator>
      <dc:date>2017-02-02T20:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: help understanding MACRO functionality</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329582#M73758</link>
      <description>Just not today! But tomorrow I probably will. &lt;BR /&gt;</description>
      <pubDate>Thu, 02 Feb 2017 20:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329582#M73758</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-02T20:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: help understanding MACRO functionality</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329586#M73760</link>
      <description>&lt;P&gt;Your last macro will work if written like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429"&gt;@LaurieF&lt;/a&gt;&amp;nbsp;suggested:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro date_loop(start,end);&lt;BR /&gt; %do i=0 %to %sysfunc(intck(month,%sysevalf("&amp;amp;start"d),%sysevalf("&amp;amp;end"d)));&lt;BR /&gt; %let date=%sysfunc(intnx(month,%sysevalf("&amp;amp;start"d),&amp;amp;i,b),date9.);&lt;BR /&gt; %put &amp;amp;date;&lt;BR /&gt; %end;&lt;BR /&gt;%mend date_loop;&lt;BR /&gt;%date_loop(01jul2015,01feb2016)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 21:03:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329586#M73760</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-02T21:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: help understanding MACRO functionality</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329697#M73821</link>
      <description>&lt;P&gt;Simplify, simplify, simplify:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro date_loop(start,end);
	%do i = 0 %to %sysfunc(intck(month, "&amp;amp;start"d, "&amp;amp;end"d));
		%let date = %sysfunc(intnx(month,"&amp;amp;start"d, &amp;amp;i, b), date9.);
		%put &amp;amp;date;
	%end;
%mend date_loop;

%date_loop(01jul2015, 01feb2016);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Feb 2017 06:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-understanding-MACRO-functionality/m-p/329697#M73821</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-03T06:25:01Z</dc:date>
    </item>
  </channel>
</rss>

