<?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 Dynamic Dates in a Macro Do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Dates-in-a-Macro-Do-loop/m-p/545365#M150850</link>
    <description>&lt;P&gt;Hi everyone&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am struggling with creating a macro that loops through a date range that is specified.&lt;/P&gt;&lt;P&gt;I would like to give my macro a start date and end date and run a piece of macro to automatically create data sets.&lt;/P&gt;&lt;P&gt;the isse is where I have to define the second date where it starts the iteration:&lt;/P&gt;&lt;P&gt;%let date=%substr(%sysfunc(intnx(month,%substr(%sysfunc(inputn(&amp;amp;start,yymmn6.),yymmn6.),1,6),1,yymmn6.),yymmn6.),1,6);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the following warning:&lt;/P&gt;&lt;P&gt;WARNING: Argument 4 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.&lt;BR /&gt;NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set to a missing value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;options symbolgen;&lt;BR /&gt;%let start='20181101'd;&lt;BR /&gt;%let end='20190201'd;&lt;BR /&gt;data _null_;&lt;BR /&gt;datestart = input("&amp;amp;start",yymmn6.);&lt;BR /&gt;dateend = input("&amp;amp;end",yymmn6.);&lt;BR /&gt;counter = intck('month',datestart,dateend)+1;&lt;BR /&gt;call symput('counter',put(counter,best.));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%macro loop;&lt;BR /&gt;%let date=%substr(%sysfunc(inputn(&amp;amp;start,yymmn6.),yymmn6.),1,6);&lt;BR /&gt;%do i=1 %to &amp;amp;counter;&lt;BR /&gt;data data_&amp;amp;date.;&lt;BR /&gt;set data_&amp;amp;date.;&lt;BR /&gt;run;&lt;BR /&gt;%let date=%substr(%sysfunc(intnx(month,%substr(%sysfunc(inputn(&amp;amp;start,yymmn6.),yymmn6.),1,6),1,yymmn6.),yymmn6.),1,6);&lt;BR /&gt;%put &amp;amp;i &amp;amp;counter &amp;amp;date;&lt;BR /&gt;%end;&lt;BR /&gt;%mend loop;&lt;BR /&gt;%loop&lt;/P&gt;</description>
    <pubDate>Fri, 22 Mar 2019 19:51:57 GMT</pubDate>
    <dc:creator>shidehrafigh</dc:creator>
    <dc:date>2019-03-22T19:51:57Z</dc:date>
    <item>
      <title>Dynamic Dates in a Macro Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Dates-in-a-Macro-Do-loop/m-p/545365#M150850</link>
      <description>&lt;P&gt;Hi everyone&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am struggling with creating a macro that loops through a date range that is specified.&lt;/P&gt;&lt;P&gt;I would like to give my macro a start date and end date and run a piece of macro to automatically create data sets.&lt;/P&gt;&lt;P&gt;the isse is where I have to define the second date where it starts the iteration:&lt;/P&gt;&lt;P&gt;%let date=%substr(%sysfunc(intnx(month,%substr(%sysfunc(inputn(&amp;amp;start,yymmn6.),yymmn6.),1,6),1,yymmn6.),yymmn6.),1,6);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the following warning:&lt;/P&gt;&lt;P&gt;WARNING: Argument 4 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.&lt;BR /&gt;NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set to a missing value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;options symbolgen;&lt;BR /&gt;%let start='20181101'd;&lt;BR /&gt;%let end='20190201'd;&lt;BR /&gt;data _null_;&lt;BR /&gt;datestart = input("&amp;amp;start",yymmn6.);&lt;BR /&gt;dateend = input("&amp;amp;end",yymmn6.);&lt;BR /&gt;counter = intck('month',datestart,dateend)+1;&lt;BR /&gt;call symput('counter',put(counter,best.));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%macro loop;&lt;BR /&gt;%let date=%substr(%sysfunc(inputn(&amp;amp;start,yymmn6.),yymmn6.),1,6);&lt;BR /&gt;%do i=1 %to &amp;amp;counter;&lt;BR /&gt;data data_&amp;amp;date.;&lt;BR /&gt;set data_&amp;amp;date.;&lt;BR /&gt;run;&lt;BR /&gt;%let date=%substr(%sysfunc(intnx(month,%substr(%sysfunc(inputn(&amp;amp;start,yymmn6.),yymmn6.),1,6),1,yymmn6.),yymmn6.),1,6);&lt;BR /&gt;%put &amp;amp;i &amp;amp;counter &amp;amp;date;&lt;BR /&gt;%end;&lt;BR /&gt;%mend loop;&lt;BR /&gt;%loop&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 19:51:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Dates-in-a-Macro-Do-loop/m-p/545365#M150850</guid>
      <dc:creator>shidehrafigh</dc:creator>
      <dc:date>2019-03-22T19:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Dates in a Macro Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Dates-in-a-Macro-Do-loop/m-p/545371#M150853</link>
      <description>&lt;P&gt;Maybe this can help.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n01vuhy8h909xgn16p0x6rddpoj9.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n01vuhy8h909xgn16p0x6rddpoj9.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm also assuming that's partial code, because what you're doing there won't change anything.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 20:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Dates-in-a-Macro-Do-loop/m-p/545371#M150853</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-03-22T20:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Dates in a Macro Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Dates-in-a-Macro-Do-loop/m-p/545374#M150854</link>
      <description>&lt;P&gt;First make sure you start with valid values. Date literals must be a a format that the DATE informat can understand.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start='01NOV2018'd;
%let end='01FEB2019'd;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to loop in macro code then increment using a normal integer based %DO loop over the offset number and use it generate a valid date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(from,to);
%local i date_raw date_fmt;
%do i=0 %to %sysfunc(intck(month,&amp;amp;from,&amp;amp;to));
  %let date_raw=%sysfunc(intnx(month,&amp;amp;from,&amp;amp;i));
  %let date_fmt=%sysfunc(intnx(month,&amp;amp;from,&amp;amp;i),date9);
  %put &amp;amp;=i &amp;amp;=date_fmt &amp;amp;=date_raw;
%end;
%mend test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;267   %test(&amp;amp;start,&amp;amp;end);
I=0 DATE_FMT=01NOV2018 DATE_RAW=21489
I=1 DATE_FMT=01DEC2018 DATE_RAW=21519
I=2 DATE_FMT=01JAN2019 DATE_RAW=21550
I=3 DATE_FMT=01FEB2019 DATE_RAW=21581
&lt;/PRE&gt;
&lt;P&gt;If you just want to use the value in code then just use the raw number of days.&amp;nbsp; If you want to use a value like 01FEB2019 in code then you need to enclose it in quotes and add a D suffix.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"&amp;amp;date_fmt"d&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 20:41:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Dates-in-a-Macro-Do-loop/m-p/545374#M150854</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-22T20:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Dates in a Macro Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-Dates-in-a-Macro-Do-loop/m-p/545578#M150944</link>
      <description>&lt;P&gt;Hi Reeza&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot! I looked for a documentation for quite a long time but I couldn't find something that would address the date issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the same code to create the previous month data for each month as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Shideh&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2019 09:24:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-Dates-in-a-Macro-Do-loop/m-p/545578#M150944</guid>
      <dc:creator>shidehrafigh</dc:creator>
      <dc:date>2019-03-24T09:24:45Z</dc:date>
    </item>
  </channel>
</rss>

