<?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 How to automate the date definition in a macro variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109521#M30473</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi community,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have to run a same SAS program everyday having macro definitions like below. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let CDATE=May08; (&lt;SPAN style="color: #ff0000;"&gt;lets call this eq. 1&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;%let PDATE=May07; (&lt;SPAN style="color: #ff0000;"&gt;lets call this eq. 2&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then macro variables named &amp;amp;CDATE and &amp;amp;PDATE&amp;nbsp; are used in several places across the SAS program. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Right hand side of eq. 1 refers to yesterday.&lt;/P&gt;&lt;P&gt;Right hand side of eq. 2 refers to day before yesterday.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am manually changing the right hand side of the eq. 1 and eq. 2 everyday.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a feeling that %sysdate automatic macro variable can be used to automate the process but fear it might upset everything in my organization.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help to automate the process is highly appreciated. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mirisage&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 09 May 2012 19:49:23 GMT</pubDate>
    <dc:creator>Mirisage</dc:creator>
    <dc:date>2012-05-09T19:49:23Z</dc:date>
    <item>
      <title>How to automate the date definition in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109521#M30473</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi community,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have to run a same SAS program everyday having macro definitions like below. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let CDATE=May08; (&lt;SPAN style="color: #ff0000;"&gt;lets call this eq. 1&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;%let PDATE=May07; (&lt;SPAN style="color: #ff0000;"&gt;lets call this eq. 2&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then macro variables named &amp;amp;CDATE and &amp;amp;PDATE&amp;nbsp; are used in several places across the SAS program. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Right hand side of eq. 1 refers to yesterday.&lt;/P&gt;&lt;P&gt;Right hand side of eq. 2 refers to day before yesterday.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am manually changing the right hand side of the eq. 1 and eq. 2 everyday.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a feeling that %sysdate automatic macro variable can be used to automate the process but fear it might upset everything in my organization.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help to automate the process is highly appreciated. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mirisage&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 19:49:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109521#M30473</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2012-05-09T19:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate the date definition in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109522#M30474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There's %sysdate and today, the problem is there isn't a predefined format that outputs the date&amp;nbsp; as monday. Do you always use a 3 letter month, is September 7, 2012 Sep07 or September07?&lt;/P&gt;&lt;P&gt;Would writing your own format be an acceptable solution and use that in combination with sysfunc?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let cdate=%sysfunc(today(), worddate12.);&lt;/P&gt;&lt;P&gt;%put cdate;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 21:01:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109522#M30474</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-05-09T21:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate the date definition in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109523#M30475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Reeza's question is an important one ... what do you want to do when the date is in September instead of May.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here are some recommendations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, leave these statements in the program:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let CDATE=;&lt;/P&gt;&lt;P&gt;%let PDATE=;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then add a DATA step to re-assign values.&amp;nbsp; The DATA step can easily check the values of &amp;amp;CDATE, &amp;amp;PDATE and &amp;amp;SYSDATE9, and act accordingly.&amp;nbsp; Some code snippets appear below.&amp;nbsp; It will be much easier to read the code in the DATA step, rather than nesting multiple %SYSFUNCs if you try to do it all in macro language.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One reason for this approach is that you will one day have a backup in your production process.&amp;nbsp; You may have to backdate the report instead of relying on using the previous day.&amp;nbsp; In that case, assign values in the %LET statements.&amp;nbsp; But the subsequent DATA step can remain in the program as is.&amp;nbsp; It can be programmed to leave &amp;amp;CDATE and &amp;amp;PDATE unchanged if they already have assigned values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OK, some code snippets.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let CDATE=;&lt;/P&gt;&lt;P&gt;%let PDATE=;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;if "&amp;amp;CDATE"=' ';&lt;/P&gt;&lt;P&gt;cdate = put("&amp;amp;sysdate9"d - 1, worddate18.);&lt;/P&gt;&lt;P&gt;pdate = put("&amp;amp;sysdate9"d - 2, worddate18.);&lt;/P&gt;&lt;P&gt;cdate = /* use DATA step functions to pull out the proper pieces of CDATE */;&lt;/P&gt;&lt;P&gt;call symputx('cdate', cdate);&lt;/P&gt;&lt;P&gt;** same for pdate;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 21:15:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109523#M30475</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-05-09T21:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate the date definition in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109524#M30476</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I prefer today() rather than %sysdate, because %sysdate doesn't update if you don't restart your SAS session overnight.&lt;/P&gt;&lt;P&gt;Depends on how you run jobs and where your computer is I suppose.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; The following code is based on Astounding's suggested method, which I like &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;c_date = today()-1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;p_date = today()-2;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cdate = put(c_date, monname9.)||put(day(c_date), z2.);&lt;/P&gt;&lt;P&gt;pdate = put(p_date, monname9.)||put(day(p_date), z2.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;call symputx('cdate', cdate);&lt;/P&gt;&lt;P&gt;call symputx('pdate', pdate);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;** same for pdate;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;cdate.;&lt;/P&gt;&lt;P&gt;%put &amp;amp;pdate.;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 21:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109524#M30476</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-05-09T21:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate the date definition in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109525#M30477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Given your example, it wasn't clear whether you want a 3 character month.&amp;nbsp; Regardless, you can do it all with %let statements.&amp;nbsp; E.g.,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let today=%sysfunc(today());&lt;/P&gt;&lt;P&gt;%let cdate = %sysfunc(putn(&amp;amp;today.-1, monname3.))%sysfunc(putn(%sysfunc(day(&amp;amp;today.))-1, z2.));&lt;/P&gt;&lt;P&gt;%let pdate = %sysfunc(putn(&amp;amp;today.-2, monname3.))%sysfunc(putn(%sysfunc(day(&amp;amp;today.))-2, z2.));&lt;/P&gt;&lt;P&gt;%put &amp;amp;cdate;&lt;/P&gt;&lt;P&gt;%put &amp;amp;pdate;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 01:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109525#M30477</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-05-10T01:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate the date definition in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109526#M30478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Hi Reeza, Astounding and Art,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Thank you very much for all three of you.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;This is a tremendous knowledge.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Thanks again!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Best regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Mirisage&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 12:44:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109526#M30478</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2012-05-10T12:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate the date definition in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109527#M30479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Art, nice job.&amp;nbsp; It's easy enough to read, and it still meets my added condition ... if the program ever needs to be backdated, the changes are limited to just a single line in the program.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 13:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109527#M30479</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-05-10T13:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate the date definition in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109528#M30480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What if today is a monday, do you really want yesterday (sunday) on your report or the previous work day (friday)?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can always use the INTNX date function to move back to the last busness day.&lt;/P&gt;&lt;P&gt;such as:&lt;/P&gt;&lt;P&gt;lstyr = intnx('WEEKDAY',today());&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are a bunch of formats and functions that work with SAS dates.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 May 2012 15:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109528#M30480</guid>
      <dc:creator>mrgibson</dc:creator>
      <dc:date>2012-05-11T15:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate the date definition in a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109529#M30481</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mrgibson,&lt;/P&gt;&lt;P&gt;You are very correct. Actually I was thinking how to incorporate last business day, because I needed the last business day, and not just yesterday. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your input is certainly helpful for this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mirisage &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 12 May 2012 13:20:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-automate-the-date-definition-in-a-macro-variable/m-p/109529#M30481</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2012-05-12T13:20:40Z</dc:date>
    </item>
  </channel>
</rss>

