<?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: Macro programming for dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339196#M77387</link>
    <description>&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p09y28i2d1kn8qn1p1icxchz37p3.htm" target="_blank"&gt;call symput&lt;/A&gt; creates macro variables. Use the string supplied to the call routine as the first parameter as a macro variable reference, eg &amp;amp;today for todays's date. Note that it is the raw SAS date value (number of days from 01jan1960), hard to read for humans, but very easy to use in comparisons etc.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Mar 2017 12:36:47 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-03-08T12:36:47Z</dc:date>
    <item>
      <title>Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339178#M77378</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking to create macros in SAS that will allow me to quick reference dates in my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to have the following...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Today&amp;nbsp;&lt;/P&gt;&lt;P&gt;Today Last year&lt;/P&gt;&lt;P&gt;Today 3Mths ago&lt;/P&gt;&lt;P&gt;Today 6Mths ago&lt;/P&gt;&lt;P&gt;Today 9Mths ago&lt;/P&gt;&lt;P&gt;First Day of Prev Month&lt;/P&gt;&lt;P&gt;Last Day of Prev Month&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Cam&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 11:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339178#M77378</guid>
      <dc:creator>CamRutherford</dc:creator>
      <dc:date>2017-03-08T11:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339182#M77379</link>
      <description>&lt;P&gt;Why would you need macro when there is perfectly good functions for this:&lt;/P&gt;
&lt;P&gt;Today &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;= today()&lt;/P&gt;
&lt;P&gt;Today Last year &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;= intnx('year',today(),-1)&lt;/P&gt;
&lt;P&gt;Today 3Mths ago &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;= intnx('month',today(),-3)&lt;/P&gt;
&lt;P&gt;Today 6Mths ago &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... same&lt;/P&gt;
&lt;P&gt;Today 9Mths ago &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... same&lt;/P&gt;
&lt;P&gt;First Day of Prev Month &amp;nbsp; &amp;nbsp;= intnx('day',intnx(month,today(),-1),1,'b')&lt;/P&gt;
&lt;P&gt;Last Day of Prev Month &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;= intnx('day',intnx(month,today(),-1),1,'e')&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;There is never a need to use macro.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 11:59:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339182#M77379</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-08T11:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339183#M77380</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
date = today();
call symput('today',put(date,best.));
date = intnx('year',today(),-1,'same');
call symput('today_lst',put(date,best.));
date = intnx('month',today(),-3,'same');
call symput('today_3m',put(date,best.));
date = intnx('month',today(),-6,'same');
call symput('today_6m',put(date,best.));
date = intnx('month',today(),-9,'same');
call symput('today_9m',put(date,best.));
date = intnx('month',today(),-1,'begin');
call symput('lst_month_1st',put(date,best.));
date = intnx('month',today(),-1,'end');
call symput('lst_month_lst',put(date,best.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Put that into an include file or into a macro of your choice.&lt;/P&gt;
&lt;P&gt;(In case you put it into a macro, use call symputx with 'g')&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 11:59:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339183#M77380</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-08T11:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339184#M77381</link>
      <description>&lt;P&gt;data _NULL_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; /*=== calculate dates ===*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dt = today();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dt_3y = intnx('year',dt,-3,'same');&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dt_3m = intnx('month',dt,-3,'same');&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dt_6m =&amp;nbsp;&lt;SPAN&gt;intnx('month',dt,-6,'same');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dt_9m =&amp;nbsp;intnx('month',dt,-9,'same');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dt_fpm =&amp;nbsp; intnx('month',dt,-1,'beginning');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dt_lpm =&amp;nbsp; intnx('month',dt,-1,'end'); &amp;nbsp; &amp;nbsp; /* or = toady() - day(today()); &amp;nbsp;*/&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*=== assign dates to macro variables ===*/&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; call symput('toady',left(dt));&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; call symput('dt_3y',left(dt_3y));&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ...... &amp;nbsp; &amp;nbsp; /* choose your macro variable names and assign the dates calculated */&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 12:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339184#M77381</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-08T12:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339188#M77383</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd want a macro because I reference these dates a lot and would make my code more aesthetically pleasing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Cam&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 12:08:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339188#M77383</guid>
      <dc:creator>CamRutherford</dc:creator>
      <dc:date>2017-03-08T12:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339192#M77385</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116539"&gt;@CamRutherford&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd want a macro because I reference these dates a lot and would make my code more aesthetically pleasing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Cam&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you include my code in your autoexec, no macro is needed. The macro variables will be created in the global symbol table.&lt;/P&gt;
&lt;P&gt;"autoexec" could be:&lt;/P&gt;
&lt;P&gt;- the autoexec_usermods.sas file in your configuration&lt;/P&gt;
&lt;P&gt;- any autoexec.sas file used by a sas start script/command (ie sasbatch)&lt;/P&gt;
&lt;P&gt;- in the "custom code" to be sent when a server connection is opened in Enterprise Guide&lt;/P&gt;
&lt;P&gt;- in a "autoexec" process flow in your EG projects&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 12:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339192#M77385</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-08T12:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339193#M77386</link>
      <description>How would I reference each date though?</description>
      <pubDate>Wed, 08 Mar 2017 12:24:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339193#M77386</guid>
      <dc:creator>CamRutherford</dc:creator>
      <dc:date>2017-03-08T12:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339196#M77387</link>
      <description>&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p09y28i2d1kn8qn1p1icxchz37p3.htm" target="_blank"&gt;call symput&lt;/A&gt; creates macro variables. Use the string supplied to the call routine as the first parameter as a macro variable reference, eg &amp;amp;today for todays's date. Note that it is the raw SAS date value (number of days from 01jan1960), hard to read for humans, but very easy to use in comparisons etc.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 12:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339196#M77387</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-08T12:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339200#M77389</link>
      <description>&lt;P&gt;You may believe that macro is more aesthetically pleasing, I would just call it obfuscation. &amp;nbsp;SAS Programmers should all know or be able to look up the methodology of the various functions within Base SAS - this being the programming language. &amp;nbsp;They would not however know all about your particular mass of %&amp;amp;'s. &amp;nbsp;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;has stated you can use the code in a datastep to generate the required macro parameters, but do bear in mind these will be character, and you will always have to convert each time you want to use them further. &amp;nbsp;For instance, if you wanted yesterday, you would need:&lt;/P&gt;
&lt;P&gt;intnx('day',input("&amp;amp;my_today_value",datetime.),-1);&lt;/P&gt;
&lt;P&gt;Compare this to simple base SAS:&lt;/P&gt;
&lt;P&gt;intnx('day',today(),-1);&lt;/P&gt;
&lt;P&gt;Now add up every time you need to do that and you will see the number of processing/characters needed would in many cases exceed the benefit of storing some add-hoc dates.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 12:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339200#M77389</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-08T12:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339202#M77390</link>
      <description>&lt;P&gt;So can I not create %let satatements for each date I will want to use?&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 12:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339202#M77390</guid>
      <dc:creator>CamRutherford</dc:creator>
      <dc:date>2017-03-08T12:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339203#M77391</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; keep in mind that I deliberately use the best. format for my "date" macro variables, so the raw values can be directly used in comparisons and calculations.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 12:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339203#M77391</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-08T12:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339206#M77392</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116539"&gt;@CamRutherford&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;So can I not create %let satatements for each date I will want to use?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Of course you can. But look at this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lst_year=%sysfunc(intnx(year,%sysfunc(today()),-1,same),best.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;vs&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
date = intnx('year',today(),-1,'same');
call symput('lst_year',put(date,best.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and tell me which is easier to decipher.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS I forgot to mention that both examples create identical macro variables.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 13:03:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339206#M77392</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-08T13:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339210#M77393</link>
      <description>DO YOU MEAN...&lt;BR /&gt;&lt;BR /&gt;%let lst_year=%sysfunc(intnx(month,%sysfunc(today()),-1,same)),best.));</description>
      <pubDate>Wed, 08 Mar 2017 13:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339210#M77393</guid>
      <dc:creator>CamRutherford</dc:creator>
      <dc:date>2017-03-08T13:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339215#M77395</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116539"&gt;@CamRutherford&lt;/a&gt; wrote:&lt;BR /&gt;DO YOU MEAN...&lt;BR /&gt;&lt;BR /&gt;%let lst_year=%sysfunc(intnx(month,%sysfunc(today()),-1,same)),best.));&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yep. Changed my post. My maxim is that if there is more than one %sysfunc in a statement, I switch to a data step to get rid of the %sysfuncs.&lt;/P&gt;
&lt;P&gt;This also makes your code easier to maintain, as more complex logic doesn't become as unwieldy in a data step as it does in a macro %let.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 13:12:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339215#M77395</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-08T13:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339277#M77404</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116539"&gt;@CamRutherford&lt;/a&gt; wrote:&lt;BR /&gt;How would I reference each date though?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I do something along these lines with a call in my autoexec to create a macro variable with a specific format that I use in title statements. The varible created is named prepdate. When I want to use it:&lt;/P&gt;
&lt;P&gt;title2 "Prepared on: &amp;amp;prepdate";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't mention HOW you intend to use any of these variables. Do you want TEXT that is human readable or the Values that are used in comparisons (or possibly both which would work best with 2 variables, one for text and one for value).&lt;/P&gt;</description>
      <pubDate>Wed, 08 Mar 2017 15:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339277#M77404</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-08T15:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro programming for dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339326#M77408</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116539"&gt;@CamRutherford&lt;/a&gt;, I quote your posts:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;I'd want a macro because I reference these dates a lot &lt;BR /&gt;
and:

How would I reference each date though?&lt;/PRE&gt;
&lt;P&gt;You should be aware of two different terms: macro program and macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Within a macro program you can generate sas code according to arguments given.&lt;/P&gt;
&lt;P&gt;Macro variables can be craeted in various ways: by a datastep or by %let statement.&lt;/P&gt;
&lt;P&gt;The last can be either in or out of a macro program.&lt;/P&gt;
&lt;P&gt;And be aware that macro variable can be global, available anywhere in your sas session or&lt;/P&gt;
&lt;P&gt;local. ie available only inside a specific macro program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case, you want several macro variables, each per different date.&lt;/P&gt;
&lt;P&gt;You got some posts how to do it by a datastep.&lt;/P&gt;
&lt;P&gt;The call symput statement assingns a value to a macro variable.&lt;/P&gt;
&lt;P&gt;I quote here my code posted, leaving you to complete more assignments as you like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
  /*=== calculate dates ===*/
       dt = today();
       dt_1y = intnx('year',dt,-1,'same');
       dt_3m = intnx('month',dt,-3,'same');
       dt_6m = intnx('month',dt,-6,'same');
       dt_9m = intnx('month',dt,-9,'same');
       dt_fpm =  intnx('month',dt,-1,'beginning');
       dt_lpm =  intnx('month',dt,-1,'end');     /* or = toady() - day(today());  */
 
/*=== assign dates to macro variables ===*/
      call symput('toady',left(dt));
      call symput('dt_1y',left(dt_1y));&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;      call symput('dt_3m',left(dt_3m));&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;      ...... /* choose your macro variable names and assign the dates calculated */ &lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;today &amp;amp;dt_3y  &amp;amp;dt_3m;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Run the code and check the log. The numbers you got is the eqivalent to dates calculated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to the question how you use it, here is a demo:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  today = &amp;amp;today;
  put today ddmmyy10.;

  dt_1y = &amp;amp;dt_1y;
  put 'today last year = ' dt_1y ddmmyy10.;

   tdr = &amp;amp;dt_3m;
   put 'Today 3Mths ago  = ' tdr date9.;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Mar 2017 17:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-programming-for-dates/m-p/339326#M77408</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-08T17:15:36Z</dc:date>
    </item>
  </channel>
</rss>

