<?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 Variables using the today() statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables-using-the-today-statement/m-p/34686#M6835</link>
    <description>Hi Spud.&lt;BR /&gt;
Instead of hard coding today's date and substracting from it, you can let SAS do computations. You can do that with the %SYSFUNC macro function, but it becomes a little boring when you have more than you function to access at a time. So what I think is the most simple solution is to create dates in a Data step, and then record their values, using the Call Symput routine. You can use functions as INTNX to build last month's date, and formats to extract parts of the information.&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA _NULL_ ;&lt;BR /&gt;
	today = TODAY() ;&lt;BR /&gt;
	lastMonth = INTNX("MONTH", today, -1) ;&lt;BR /&gt;
	CALL SYMPUT("tday", PUT(today, DDMMYYN8.)) ;&lt;BR /&gt;
	CALL SYMPUT("yyyy", PUT(today, YEAR4.)) ;&lt;BR /&gt;
	CALL SYMPUT("yyyy2", PUT(lastMonth, YEAR4.)) ;&lt;BR /&gt;
	CALL SYMPUT("mm", PUT(MONTH(today),Z2.)) ;&lt;BR /&gt;
	CALL SYMPUT("mm2", PUT(MONTH(lastMonth),Z2.)) ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
%PUT _USER_ ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Regards&lt;BR /&gt;
Olivier</description>
    <pubDate>Mon, 28 Jul 2008 18:34:58 GMT</pubDate>
    <dc:creator>Olivier</dc:creator>
    <dc:date>2008-07-28T18:34:58Z</dc:date>
    <item>
      <title>Macro Variables using the today() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables-using-the-today-statement/m-p/34685#M6834</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
Im trying to have 5 macro variables, &lt;BR /&gt;
%tday which contains todays full date&lt;BR /&gt;
%yyyy which contains todays year as 4 digits&lt;BR /&gt;
%yyyy2 which contains last months year as 4 digits&lt;BR /&gt;
%mm which contains todays month as 2 digits&lt;BR /&gt;
%mm2 which contains last months month as 2 digits.&lt;BR /&gt;
for eg todays(28/07/2008) would be&lt;BR /&gt;
tday=28072008&lt;BR /&gt;
yyyy=2008&lt;BR /&gt;
yyyy2=2008&lt;BR /&gt;
mm=07&lt;BR /&gt;
mm2=06&lt;BR /&gt;
But if for eg todays date was 15/01/2009 is where i get my problem!&lt;BR /&gt;
&lt;BR /&gt;
Please help&lt;BR /&gt;
&lt;BR /&gt;
Thanks &lt;BR /&gt;
Spud</description>
      <pubDate>Mon, 28 Jul 2008 16:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables-using-the-today-statement/m-p/34685#M6834</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-07-28T16:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variables using the today() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables-using-the-today-statement/m-p/34686#M6835</link>
      <description>Hi Spud.&lt;BR /&gt;
Instead of hard coding today's date and substracting from it, you can let SAS do computations. You can do that with the %SYSFUNC macro function, but it becomes a little boring when you have more than you function to access at a time. So what I think is the most simple solution is to create dates in a Data step, and then record their values, using the Call Symput routine. You can use functions as INTNX to build last month's date, and formats to extract parts of the information.&lt;BR /&gt;
[pre]&lt;BR /&gt;
DATA _NULL_ ;&lt;BR /&gt;
	today = TODAY() ;&lt;BR /&gt;
	lastMonth = INTNX("MONTH", today, -1) ;&lt;BR /&gt;
	CALL SYMPUT("tday", PUT(today, DDMMYYN8.)) ;&lt;BR /&gt;
	CALL SYMPUT("yyyy", PUT(today, YEAR4.)) ;&lt;BR /&gt;
	CALL SYMPUT("yyyy2", PUT(lastMonth, YEAR4.)) ;&lt;BR /&gt;
	CALL SYMPUT("mm", PUT(MONTH(today),Z2.)) ;&lt;BR /&gt;
	CALL SYMPUT("mm2", PUT(MONTH(lastMonth),Z2.)) ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
%PUT _USER_ ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Regards&lt;BR /&gt;
Olivier</description>
      <pubDate>Mon, 28 Jul 2008 18:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables-using-the-today-statement/m-p/34686#M6835</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2008-07-28T18:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variables using the today() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables-using-the-today-statement/m-p/34687#M6836</link>
      <description>Thanks Olivier&lt;BR /&gt;
&lt;BR /&gt;
It worked a treat!</description>
      <pubDate>Thu, 31 Jul 2008 15:10:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables-using-the-today-statement/m-p/34687#M6836</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-07-31T15:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variables using the today() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables-using-the-today-statement/m-p/34688#M6837</link>
      <description>Last question if i want a 3 letter month what would be the format?</description>
      <pubDate>Mon, 04 Aug 2008 09:32:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables-using-the-today-statement/m-p/34688#M6837</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-04T09:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variables using the today() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variables-using-the-today-statement/m-p/34689#M6838</link>
      <description>You have a choice, either use the SAS FORMAT MONNAME or WORDDATE with the trailing length specification to truncate the displayed value.  If you need the string in uppercase (as I do often), assign a SAS character variable and use the UPCASE function and the PUT function with the desired format.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
___________________&lt;BR /&gt;
&lt;BR /&gt;
SAS 913 DOC - MONNAME format (with examples!):&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000201049.htm" target="_blank"&gt;http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000201049.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
SAS 913 DOC - FORMATS chapter in SAS Language Reference: Dictionary&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000309859.htm" target="_blank"&gt;http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000309859.htm&lt;/A&gt;</description>
      <pubDate>Mon, 04 Aug 2008 15:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variables-using-the-today-statement/m-p/34689#M6838</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-08-04T15:51:22Z</dc:date>
    </item>
  </channel>
</rss>

