<?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: looping through dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436855#M108707</link>
    <description>&lt;P&gt;thanks but I can't use a number. The start month and end month will be different&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Feb 2018 20:37:45 GMT</pubDate>
    <dc:creator>CP2</dc:creator>
    <dc:date>2018-02-13T20:37:45Z</dc:date>
    <item>
      <title>looping through dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436844#M108701</link>
      <description>&lt;P&gt;I am trying to create a small database of months from one date to another, incrementing by month. I want three observations:&lt;/P&gt;&lt;P&gt;10/1/2017&lt;/P&gt;&lt;P&gt;11/1/2017&lt;/P&gt;&lt;P&gt;12/1/2017&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following code just gives me 10/1/2017 and doesn't loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Assume:&lt;/P&gt;&lt;P&gt;%Let maxmth=01SEP2017;&lt;/P&gt;&lt;P&gt;%Let maxdt=01DEC2017;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data addMonths ;&lt;BR /&gt;format month MMDDYY10. ;&lt;BR /&gt;month=intnx('month',%unquote(%str(%')&amp;amp;maxmth.%str(%'d)),1) ;&lt;BR /&gt;put month ;&lt;BR /&gt;DO i = (month &amp;lt;= %unquote(%str(%')&amp;amp;maxdt.%str(%'d))) ;&lt;BR /&gt;output ;&lt;BR /&gt;month=intnx('month',month,1) ;&lt;BR /&gt;put month;&lt;BR /&gt;END;&lt;BR /&gt;run;&lt;BR /&gt;proc print ; run;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 19:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436844#M108701</guid>
      <dc:creator>CP2</dc:creator>
      <dc:date>2018-02-13T19:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: looping through dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436846#M108703</link>
      <description>&lt;P&gt;Before we address the loop issue, I would like to know why the fancy macro syntax in a datastep? what's the need?Why call macro processor and play with tokens?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why can't it be easy and simple like&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let maxmth=01SEP2017;

%Let maxdt=01DEC2017;

data addMonths ;
format month MMDDYY10. ;
month=intnx('month',"&amp;amp;maxmth"d,1) ;
put month =;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Feb 2018 20:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436846#M108703</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-13T20:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: looping through dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436852#M108704</link>
      <description>&lt;P&gt;The fancy macros aren't necessary. I've been switching back and forth between doing sql pass through which thinks anything in double quotes is a column thus the need to do something for a single quote when using a date in the where statement of sql pass through, so I just wasn't thinking for this particular data step task which can use the double quotes. This needs to be automated so the maxmth is a macro variable that will be called based on the last existing month we have data for and the maxdt macro variable will be any month in the future edited by a user. I still need a simple list of new months with the loop based on a start month and an end month. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 20:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436852#M108704</guid>
      <dc:creator>CP2</dc:creator>
      <dc:date>2018-02-13T20:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: looping through dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436853#M108705</link>
      <description>&lt;P&gt;Here's one way. No macro needed, will allow for just about as many months as you are likely to want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data dateloop;
   startdate='01SEP2017'd;
   do i= 1 to 3; /*3 being the number of months you want*/
      wantdate=startdate;
      output;
      startdate=intnx('month',startdate,1,'B');
   end;
   format wantdate date9.;
   drop startdate;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Feb 2018 20:31:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436853#M108705</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-13T20:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: looping through dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436854#M108706</link>
      <description>&lt;P&gt;My version:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;do _n_=0 to 5000 until (date &amp;gt;= "&amp;amp;maxdt"d) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; date = intnx('month', "&amp;amp;maxmth"d, _n_) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;format date mmddyys10.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The loop won't really iterate 5000 times ... it's just a safeguard in case wonky dates are entered that would cause the Until condition to remain false.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 20:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436854#M108706</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-13T20:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: looping through dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436855#M108707</link>
      <description>&lt;P&gt;thanks but I can't use a number. The start month and end month will be different&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 20:37:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436855#M108707</guid>
      <dc:creator>CP2</dc:creator>
      <dc:date>2018-02-13T20:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: looping through dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436859#M108709</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/59791"&gt;@CP2&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;thanks but I can't use a number. The start month and end month will be different&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use INTCK to figure out the number of months you need first. Then use a DO loop.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 20:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looping-through-dates/m-p/436859#M108709</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-13T20:47:17Z</dc:date>
    </item>
  </channel>
</rss>

