<?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: Using the today() function in a data null step. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360791#M85013</link>
    <description>&lt;P&gt;If you used the code in the answered that is marked as correct there is no macro variable created by that code. You could add a CALL SYMPUTX() statement to make one if you want. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that SAS dates are number of days. So no need to use the INTNX() function to add/subtract days.&lt;/P&gt;
&lt;P&gt;You can use the automatic macro variable SYSDATE9 which should have the date the SAS session started in DATE9 format. &amp;nbsp;If you have long running sessions&amp;nbsp;that could span multiple days and you really need the date that this block of code started then you could use the DATE() function (or it's alias the TODAY() function).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let bcfend = &amp;amp;sysdate9;
%let days = 8;
data _null_;
  call symputx('bcfstart',put("&amp;amp;bcfend"d - &amp;amp;days,date9.));
run;
title3 "Date range &amp;amp;bcfstart to &amp;amp;bcfend";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If you are running inside of a macro that is ended before your TITLE statement runs then you might need to add the optional third parameter to make sure it generates a GLOBAL macro variable. &amp;nbsp;Without that if the macro variable does not already exist then CALL SYMPUTX() will make it in the symbol table for the macro and it will disappear when the macro finishes running.&lt;/P&gt;</description>
    <pubDate>Tue, 23 May 2017 15:22:54 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-05-23T15:22:54Z</dc:date>
    <item>
      <title>Using the today() function in a data null step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360677#M84974</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having an error when trying to run this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; bcfdate = today();&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; days = 8;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;_null_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; bcfstart=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(intnx("day",&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;bcfdate.),-&amp;amp;days.));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;bcfstart.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;I believe that the today() function cannot be processed in the data _null_ statement and therefore "bcfstart" cannot be calculated&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;Does anyone have any ideas on how to get around this issue?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;Cheers.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 10:53:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360677#M84974</guid>
      <dc:creator>PriyaL</dc:creator>
      <dc:date>2017-05-23T10:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using the today() function in a data null step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360678#M84975</link>
      <description>&lt;P&gt;Why are you storing today() in a macro variable?&lt;/P&gt;
&lt;P&gt;If this is the first thing that happens in your session, use "&amp;amp;Sysdate"d instead.&lt;/P&gt;
&lt;P&gt;Also, %sysfunc should be used in open code, not within a data step.&lt;/P&gt;
&lt;P&gt;Please look at more examples on how to use %sysfunc, intnx, today() etc.&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 11:01:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360678#M84975</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-05-23T11:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using the today() function in a data null step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360679#M84976</link>
      <description>&lt;P&gt;I believe this is what you want and a bit simpler&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let days = 8;

data _null_;
	format bcfstart date9.;
	bcfstart=intnx("day",today(),-&amp;amp;days.);
	put bcfstart;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 May 2017 11:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360679#M84976</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-05-23T11:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using the today() function in a data null step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360684#M84977</link>
      <description>&lt;P&gt;A macro statement is resolved before the other SAS code is interpreted. So the data step ends up as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is, of course, totally useless.&lt;/P&gt;
&lt;P&gt;So let's look at the macro statement that you wrote into the data step code (not into the data step, mind!).&lt;/P&gt;
&lt;P&gt;After resolution of the two macro variables, we get&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let bcfstart=%sysfunc(intnx("day",%sysfunc(today()),-8));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that you wrote &lt;EM&gt;"day"&lt;/EM&gt;, not &lt;EM&gt;day&lt;/EM&gt; without quotes. The macro processor knows only one datatype, text, and therefore does not need quotes around strings. If quotes are used, they become &lt;U&gt;part of the string&lt;/U&gt;, so what is fed to the datastep function within the %sysfunc will appear as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx('"day"',&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is invalid syntax and gets you a&lt;/P&gt;
&lt;PRE&gt;WARNING: Argument 1 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.&lt;/PRE&gt;
&lt;P&gt;which basically says it all.&lt;/P&gt;
&lt;P&gt;Maxim 2: Read the LOG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to do your calculation in a data step (for easier reading), do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let bcfdate = %sysfunc(today());
%let days = 8;

data _null_;
bcfstart = intnx("day",&amp;amp;bcfdate.,-&amp;amp;days.);
call symput('bcfstart',put(bcfstart,best.));
run;

%put &amp;amp;bcfstart.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will see that &amp;amp;bcfstart now contains the raw value for the intended date, which is perfectly fine for date calculations later in the code.&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 11:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360684#M84977</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-23T11:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using the today() function in a data null step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360694#M84981</link>
      <description>&lt;P&gt;Doesn't make sense on several levels. &amp;nbsp;First today() is a base SAS function you can use anywhere, creating a macro variable doesn't make sense here as you can just replace that macro variable with today(). &amp;nbsp;A simple way of doing this is:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  call symputx('bcfstart',today()+8;
run;&lt;/PRE&gt;
&lt;P&gt;Although there really isn't a point in that either as you can just put: today()+8 anywhere you need it for the same effect - i.e. creating code for no reason.&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 12:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360694#M84981</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-23T12:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using the today() function in a data null step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360731#M84992</link>
      <description>&lt;P&gt;Thanks for your solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this a local macro variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is just that I need to use this in a title as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;title3&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;"Date range &amp;amp;bcfstart to &amp;amp;bcfend"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;And SAS does not seem to pick up these macros.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;Thanks.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 13:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360731#M84992</guid>
      <dc:creator>PriyaL</dc:creator>
      <dc:date>2017-05-23T13:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using the today() function in a data null step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360745#M84998</link>
      <description>&lt;P&gt;You may not need macro variables at all.&amp;nbsp; Some folks feel pure macro code can be hard to read.&amp;nbsp; But I don't mind it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;101  %put %sysfunc(intnx(day,%sysfunc(today()),-8),mmddyy10);
05/15/2017
102  %put %sysfunc(intnx(day,%sysfunc(today()),8),mmddyy10);
05/31/2017
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want macro variables for bcfdate and day, just make sure bcfdate is assigned a SAS date value, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;103  %let bcfdate=%sysfunc(today());
104  %let days=8;
105  %put %sysfunc(intnx(day,&amp;amp;bcfdate,-&amp;amp;days),mmddyy10);
05/15/2017
106  %put %sysfunc(intnx(day,&amp;amp;bcfdate,&amp;amp;days),mmddyy10);
05/31/2017
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use that in a title statement as well:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;title3 "Date range %sysfunc(intnx(day,&amp;amp;bcfdate,-&amp;amp;days),mmddyy10) to %sysfunc(intnx(day,&amp;amp;bcfdate,&amp;amp;days),mmddyy10)";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if you really wanted to, you could make a little macro function to do the work for you.&amp;nbsp; Some would say that is overkill.&amp;nbsp; But if you need to create relative dates often, it might make sense.&amp;nbsp; Peter Crawford has a great paper on a %now macro:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi31/038-31.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi31/038-31.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 14:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360745#M84998</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-05-23T14:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using the today() function in a data null step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360752#M85001</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;
  call execute(cat('title3 "Date range ',put(date(),date9.),' to ',put(date()+8,date9.),'";'));
run;&lt;/PRE&gt;
&lt;P&gt;Or if you really want to use macro variables:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  call symputx('title',(cat('title3 "Date range ',put(date(),date9.),' to ',put(date()+8,date9.),'";')));
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 14:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360752#M85001</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-23T14:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using the today() function in a data null step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360758#M85004</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/63425"&gt;@PriyaL&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this a local macro variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is just that I need to use this in a title as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff" size="3"&gt;title3&lt;/FONT&gt; &lt;FONT face="Courier New" color="#800080" size="3"&gt;"Date range &amp;amp;bcfstart to &amp;amp;bcfend"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;And SAS does not seem to pick up these macros.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;Thanks.&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Any macro variable created inside a macro will be in the local macro table and vanish after the macro has executed. Only variables that already existed in the global table, or were created with call symputx and the 'g' option, or named in a %global statement will be global.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So it depends on where you create the macro variables.&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 14:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360758#M85004</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-23T14:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using the today() function in a data null step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360791#M85013</link>
      <description>&lt;P&gt;If you used the code in the answered that is marked as correct there is no macro variable created by that code. You could add a CALL SYMPUTX() statement to make one if you want. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that SAS dates are number of days. So no need to use the INTNX() function to add/subtract days.&lt;/P&gt;
&lt;P&gt;You can use the automatic macro variable SYSDATE9 which should have the date the SAS session started in DATE9 format. &amp;nbsp;If you have long running sessions&amp;nbsp;that could span multiple days and you really need the date that this block of code started then you could use the DATE() function (or it's alias the TODAY() function).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let bcfend = &amp;amp;sysdate9;
%let days = 8;
data _null_;
  call symputx('bcfstart',put("&amp;amp;bcfend"d - &amp;amp;days,date9.));
run;
title3 "Date range &amp;amp;bcfstart to &amp;amp;bcfend";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If you are running inside of a macro that is ended before your TITLE statement runs then you might need to add the optional third parameter to make sure it generates a GLOBAL macro variable. &amp;nbsp;Without that if the macro variable does not already exist then CALL SYMPUTX() will make it in the symbol table for the macro and it will disappear when the macro finishes running.&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 15:22:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-today-function-in-a-data-null-step/m-p/360791#M85013</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-05-23T15:22:54Z</dc:date>
    </item>
  </channel>
</rss>

