<?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: Iterating Dates in a Do Loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/432609#M107159</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data junk;
 format date date9.;
  do Date = '01JUL1980'd to today()&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt; by 'month'&lt;/STRONG&gt;&lt;/FONT&gt;;
   output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;May be you know, can we do something like this? For example, i need only end of month dates. How to do that?&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2018 05:05:04 GMT</pubDate>
    <dc:creator>kanivan51</dc:creator>
    <dc:date>2018-01-31T05:05:04Z</dc:date>
    <item>
      <title>Iterating Dates in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8121#M221</link>
      <description>Anybody know how to create a list of dates (date9.) starting at a specified date and ending on the present date?  The start date will be given by proc sql and I need every possible date between then and the present date.&lt;BR /&gt;
&lt;BR /&gt;
To give context, I'm trying to run a query to get a snapshot of information at a point in time starting from the beginning of my company until the present.&lt;BR /&gt;
&lt;BR /&gt;
From there, I plan on iterating through this list in a macro so I'll be creating the list similar to:&lt;BR /&gt;
&lt;BR /&gt;
select unit_pk into :Units1 - :Units99999&lt;BR /&gt;
from PossibleUnits;</description>
      <pubDate>Tue, 27 Oct 2009 18:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8121#M221</guid>
      <dc:creator>StephenOverton</dc:creator>
      <dc:date>2009-10-27T18:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Dates in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8122#M222</link>
      <description>Dates variables are just the number of days since january 1 1960 so all you need to do is a do loop;&lt;BR /&gt;
&lt;BR /&gt;
data junk;&lt;BR /&gt;
  format date date9.;&lt;BR /&gt;
  do Date =  '01JUL1980'd to today();&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 27 Oct 2009 18:58:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8122#M222</guid>
      <dc:creator>CurtisMack</dc:creator>
      <dc:date>2009-10-27T18:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Dates in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8123#M223</link>
      <description>On looking at your example a little more.  This may be closer to what you are looking for.&lt;BR /&gt;
&lt;BR /&gt;
%macro test;&lt;BR /&gt;
%let startdate = %sysfunc(mdy(7,1,1980));&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select unit_pk into %do Date =  &amp;amp;startdate %to %sysfunc(today());&lt;BR /&gt;
                      %if &amp;amp;Date ne &amp;amp;startdate %then %str(,); &lt;BR /&gt;
                      :UNIT_%sysfunc(putn(&amp;amp;Date,DATE9.))&lt;BR /&gt;
                    %end;&lt;BR /&gt;
from PossibleUnits; &lt;BR /&gt;
quit;&lt;BR /&gt;
%mend;&lt;BR /&gt;
options mprint;&lt;BR /&gt;
%test;</description>
      <pubDate>Tue, 27 Oct 2009 19:08:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8123#M223</guid>
      <dc:creator>CurtisMack</dc:creator>
      <dc:date>2009-10-27T19:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Dates in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8124#M224</link>
      <description>I'm not as skilled as you, this is what I did with your first post:&lt;BR /&gt;
&lt;BR /&gt;
/* load dates */&lt;BR /&gt;
data dates;&lt;BR /&gt;
  format date date9.;&lt;BR /&gt;
  do date = '15SEP1999'd to today();&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
/* load dates into macro variable */&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select "'"||put(date,date9.)||"'d" into :dates1 - :dates99999&lt;BR /&gt;
  from dates;&lt;BR /&gt;
quit;</description>
      <pubDate>Tue, 27 Oct 2009 20:10:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8124#M224</guid>
      <dc:creator>StephenOverton</dc:creator>
      <dc:date>2009-10-27T20:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Dates in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8125#M225</link>
      <description>My last piece is figured out how to insert this date into the table I'm updating.  Anybody know how to do a proc sql insert using a select clause AND some static value?&lt;BR /&gt;
&lt;BR /&gt;
Ex (where 'dates' in the macro variable):&lt;BR /&gt;
%macro iterate;&lt;BR /&gt;
  %do x=1 %to &amp;amp;cntdates;&lt;BR /&gt;
    proc sql;&lt;BR /&gt;
      insert into PenetrationHistory&lt;BR /&gt;
            &amp;amp;&amp;amp;dates&amp;amp;x,&lt;BR /&gt;
	    select  [A BUNCH OF STUFF IS SELECTED HERE] ;&lt;BR /&gt;
  %end;&lt;BR /&gt;
%mend iterate;</description>
      <pubDate>Tue, 27 Oct 2009 20:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8125#M225</guid>
      <dc:creator>StephenOverton</dc:creator>
      <dc:date>2009-10-27T20:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Dates in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8126#M226</link>
      <description>wait wait, I'm an idiot...its this..&lt;BR /&gt;
&lt;BR /&gt;
%macro iterate;&lt;BR /&gt;
%do x=1 %to &amp;amp;cntdates;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
insert into PenetrationHistory&lt;BR /&gt;
select&lt;BR /&gt;
&amp;amp;&amp;amp;dates&amp;amp;x as audit_date,&lt;BR /&gt;
[rest of stuff]&lt;BR /&gt;
;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend iterate;&lt;BR /&gt;
&lt;BR /&gt;
Just moved the &amp;amp;&amp;amp;dates&amp;amp;x as audit_date inside the select clause.

more</description>
      <pubDate>Tue, 27 Oct 2009 20:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8126#M226</guid>
      <dc:creator>StephenOverton</dc:creator>
      <dc:date>2009-10-27T20:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Dates in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8127#M227</link>
      <description>Here is my last problem (I hope):&lt;BR /&gt;
&lt;BR /&gt;
I stored the dates I'm iterating though as this:  '15SEP1999'd&lt;BR /&gt;
&lt;BR /&gt;
I need to convert these back to strings but I can't get this function working:&lt;BR /&gt;
&lt;BR /&gt;
%substr(&amp;amp;&amp;amp;dates&amp;amp;x,2,9) as audit_date&lt;BR /&gt;
&lt;BR /&gt;
In the code:&lt;BR /&gt;
%macro iterate;&lt;BR /&gt;
%do x=1 %to &amp;amp;cntdates;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
insert into PenetrationHistory&lt;BR /&gt;
select&lt;BR /&gt;
%substr(&amp;amp;&amp;amp;dates&amp;amp;x,2,9) as audit_date,&lt;BR /&gt;
[rest of stuff]&lt;BR /&gt;
;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend iterate;</description>
      <pubDate>Tue, 27 Oct 2009 20:26:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8127#M227</guid>
      <dc:creator>StephenOverton</dc:creator>
      <dc:date>2009-10-27T20:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Dates in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8128#M228</link>
      <description>Once again, I figured it out.&lt;BR /&gt;
&lt;BR /&gt;
Disregard my last question, everything is good now!</description>
      <pubDate>Tue, 27 Oct 2009 20:36:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/8128#M228</guid>
      <dc:creator>StephenOverton</dc:creator>
      <dc:date>2009-10-27T20:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Dates in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/432609#M107159</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data junk;
 format date date9.;
  do Date = '01JUL1980'd to today()&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt; by 'month'&lt;/STRONG&gt;&lt;/FONT&gt;;
   output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;May be you know, can we do something like this? For example, i need only end of month dates. How to do that?&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 05:05:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/432609#M107159</guid>
      <dc:creator>kanivan51</dc:creator>
      <dc:date>2018-01-31T05:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Dates in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/860092#M339790</link>
      <description>&lt;P&gt;to calculate the end of the month use the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;end_month = intnx("month", today(), -1, 'E');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm searching something similar to your question but the increment between the dates for my case should be monthly instead of daily.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 07:44:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/860092#M339790</guid>
      <dc:creator>lvalencia</dc:creator>
      <dc:date>2023-02-22T07:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Dates in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/860100#M339796</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436633"&gt;@lvalencia&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Start your own thread and describe what you need.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Adding on to a 13 year old thread is not improving the existing question.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 09:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/860100#M339796</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-22T09:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating Dates in a Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/860102#M339798</link>
      <description>Apologise but thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;.&lt;BR /&gt;I'm new here and a bit lost.&lt;BR /&gt;New post soon.</description>
      <pubDate>Wed, 22 Feb 2023 10:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterating-Dates-in-a-Do-Loop/m-p/860102#M339798</guid>
      <dc:creator>lvalencia</dc:creator>
      <dc:date>2023-02-22T10:02:03Z</dc:date>
    </item>
  </channel>
</rss>

