<?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: Dates and Macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dates-and-Macros/m-p/21774#M3506</link>
    <description>Thanks for the information and the solution.  I was assuming the date format was being treated as a number by default.</description>
    <pubDate>Fri, 30 May 2008 12:57:30 GMT</pubDate>
    <dc:creator>1162</dc:creator>
    <dc:date>2008-05-30T12:57:30Z</dc:date>
    <item>
      <title>Dates and Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dates-and-Macros/m-p/21772#M3504</link>
      <description>I'm trying to convert this data step into a macro.  I can't figure out what I need to do to increment a date value in a macro.&lt;BR /&gt;
&lt;BR /&gt;
This works:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
	i = '01Oct2007'd;&lt;BR /&gt;
	do until (i &amp;gt;= '31Dec2007'd);&lt;BR /&gt;
		i = i + 7;&lt;BR /&gt;
		put i date9.;&lt;BR /&gt;
	end;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
This doesn't:&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro loop;&lt;BR /&gt;
	%let i = '01Oct2007'd;&lt;BR /&gt;
	%do %until (&amp;amp;i &amp;gt;= '31Dec2007'd);&lt;BR /&gt;
		%let i = %eval(&amp;amp;i + 7);&lt;BR /&gt;
		%put &amp;amp;i;&lt;BR /&gt;
	%end;&lt;BR /&gt;
%mend loop;&lt;BR /&gt;
%loop;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
I'm pretty sure the problem is with the %eval part, but I'm not sure what the correct syntax should be.&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance for your help</description>
      <pubDate>Thu, 29 May 2008 16:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dates-and-Macros/m-p/21772#M3504</guid>
      <dc:creator>1162</dc:creator>
      <dc:date>2008-05-29T16:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dates and Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dates-and-Macros/m-p/21773#M3505</link>
      <description>%macro loop;	&lt;BR /&gt;
%let i = %sysfunc(putn('01Oct2007'd,8.));&lt;BR /&gt;
%do %until (&amp;amp;i &amp;gt;= %sysfunc(putn('31Dec2007'd,8.)));		&lt;BR /&gt;
  %let i = %eval(&amp;amp;i + 7);&lt;BR /&gt;
  %put %sysfunc(Putn(&amp;amp;i,date9.));&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
%mend loop;&lt;BR /&gt;
%loop;&lt;BR /&gt;
&lt;BR /&gt;
The trick here is knowing that macro variables are strings.  So in the 1st %let &lt;BR /&gt;
statement i was litterally '01Oct2007'd instead of the numeric value 17440&lt;BR /&gt;
Therefore adding 7 to i would not work.  By converting all your dates to the numeric equivalent with %sysfunc, you are able to increment i.  To write the date back out in the date format, you must convert in back to the text string .&lt;BR /&gt;
&lt;BR /&gt;
Hope this helps&lt;BR /&gt;
Linda</description>
      <pubDate>Thu, 29 May 2008 23:38:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dates-and-Macros/m-p/21773#M3505</guid>
      <dc:creator>LAP</dc:creator>
      <dc:date>2008-05-29T23:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: Dates and Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dates-and-Macros/m-p/21774#M3506</link>
      <description>Thanks for the information and the solution.  I was assuming the date format was being treated as a number by default.</description>
      <pubDate>Fri, 30 May 2008 12:57:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dates-and-Macros/m-p/21774#M3506</guid>
      <dc:creator>1162</dc:creator>
      <dc:date>2008-05-30T12:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dates and Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dates-and-Macros/m-p/21775#M3507</link>
      <description>:If you want a macro to treat a date constant as the corresponding number-of-days-since 1960, use the %sysevalf() like [pre]&lt;BR /&gt;
  %if %sysevalf( %&amp;amp;sysdate9"d ) gt %sysevalf( "&amp;amp;my_date"d ) %then %do; [/pre]&lt;BR /&gt;
 &lt;BR /&gt;
 &lt;BR /&gt;
Good Luck&lt;BR /&gt;
 &lt;BR /&gt;
 PeterC</description>
      <pubDate>Mon, 02 Jun 2008 20:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dates-and-Macros/m-p/21775#M3507</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2008-06-02T20:14:45Z</dc:date>
    </item>
  </channel>
</rss>

