<?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: Date and time variables in SAS macro behaviour. Date works, time does not work in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Date-and-time-variables-in-SAS-macro-behaviour-Date-works-time/m-p/236730#M14743</link>
    <description>&lt;P&gt;Hi mate, welcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've made a little change in your code and it worked as you said in the Log:&amp;nbsp;&lt;SPAN&gt;TheDate is 20408 and ThisDay is TODAY() and the diff is -11&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let TheDate= %sysfunc(datepart('16NOV2015:00:00:00'dt),best12.);
%Let ThisDay = %sysfunc(TODAY(),date9.);
%Put TheDate is &amp;amp;Dato and ThisDay is &amp;amp;Thisday and the diff is 
	%eval(%eval(%sysfunc(today(),best12.)) - %eval(&amp;amp;TheDate));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Hope this helps&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 27 Nov 2015 14:29:44 GMT</pubDate>
    <dc:creator>DartRodrigo</dc:creator>
    <dc:date>2015-11-27T14:29:44Z</dc:date>
    <item>
      <title>Date and time variables in SAS macro behaviour. Date works, time does not work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Date-and-time-variables-in-SAS-macro-behaviour-Date-works-time/m-p/236711#M14737</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;This is my first post in this community so I hope I'm in the right group.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Enterprise Guide 6.1 program on SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im struggeling to understand what is the difference between the following two code sections and why time gives an error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Let TheDate= %Sysevalf('16NOV2015'd);&lt;BR /&gt;%Let ThisDay = TODAY();&lt;BR /&gt;%Put TheDate is &amp;amp;Dato and ThisDay is &amp;amp;Thisday and the diff is %EvAL(%EVAL(&amp;amp;TheDate) - %SYSFUNC(&amp;amp;ThisDay));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LOG: TheDate is 20408 and ThisDay is TODAY() and the diff is -11&lt;BR /&gt;&lt;BR /&gt;%Let TheTime = %Sysevalf('23:49:02't);&lt;BR /&gt;%Let ThisTime = Time();&lt;BR /&gt;%Put TheTime is &amp;amp;TheTime and ThisTime is &amp;amp;ThisTime and the diff is %EVAL(%EVAL(&amp;amp;TheTime) - %sysfunc(&amp;amp;ThisTime))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LOG: ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 85742 - 35133.7005119323&amp;nbsp;&lt;/P&gt;&lt;P&gt;TheTime is 85742 and ThisTime is Time() and the diff is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2015 08:47:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Date-and-time-variables-in-SAS-macro-behaviour-Date-works-time/m-p/236711#M14737</guid>
      <dc:creator>sveinola_gundhus_tv2_no</dc:creator>
      <dc:date>2015-11-27T08:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: Date and time variables in SAS macro behaviour. Date works, time does not work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Date-and-time-variables-in-SAS-macro-behaviour-Date-works-time/m-p/236714#M14739</link>
      <description>&lt;P&gt;I would presume your problem is this, the today() part in ThisDay, which you are assuming to be a function, is actually just text, therefore when you use that macro variable the today() is just plain text and the today function doesn't get shown. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To be honest though, in this scenario, and its something I always say, why are you trying to do this in macro language? &amp;nbsp;Simply put macro language is a method for generating text sent to the compiler. &amp;nbsp;It's really not built to handle data processing. &amp;nbsp;If you have to do it like this, then something like:&lt;/P&gt;
&lt;PRE&gt;%Let TheDate=16NOV2015;

data _null_;
  call symput('ThisDay',put(today(),date9.));
  call symput('Result',put("&amp;amp;TheDate."d - today(),date9.));
run;

%put TheDate is &amp;amp;TheDate, and ThisDay is &amp;amp;ThisDay. and the diff is &amp;amp;Result.;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2015 09:51:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Date-and-time-variables-in-SAS-macro-behaviour-Date-works-time/m-p/236714#M14739</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-11-27T09:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: Date and time variables in SAS macro behaviour. Date works, time does not work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Date-and-time-variables-in-SAS-macro-behaviour-Date-works-time/m-p/236715#M14740</link>
      <description>&lt;P&gt;First of all, welcome to the community!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's a minor inconsistency in the code you have provided: "&amp;amp;Dato" must read "&amp;amp;TheDate" (case insensitive, though). Otherwise, SAS would have complained about the non-existent macro variable Dato.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks to the application of %SYSEVALF in the definition of TheDate, this macro variable TheDate contains the value 20408. Hence, the inner "%EVAL" in your %PUT statement is redundant. (There is no need to "evaluate" the pure number again.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data step function call TODAY() is stored as text in macro variable ThisDay, as you see in the result of the %PUT statement and it is executed only when %SYSFUNC is applied. The result is the current SAS date value, an integer, today (on 27 Nov 2015) 20419. The outer "%EVAL" performs the calculation of 20408 minus 20419 equals -11.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similar situation with time, but the difference is that the data step function TIME() in general returns the current time including fractions of a second, i.e. not an integer, but a floating-point number. While &amp;amp;TheTime contains the integer value 85742 (=number of seconds from 00:00:00 to 23:49:02), %sysfunc(&amp;amp;ThisTime) results in a floating-point number. The %EVAL function, however, can only&amp;nbsp;evaluate &lt;EM&gt;integer&lt;/EM&gt; arithmetic or logical expressions, hence the error when trying to calculate the time difference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just replace the outer "%EVAL" by "%SYSEVALF" (which is capable of floating-point arithmetic) and you will get the intended&amp;nbsp;result. (Again, the inner "%EVAL" is redundant.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2015 10:00:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Date-and-time-variables-in-SAS-macro-behaviour-Date-works-time/m-p/236715#M14740</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-27T10:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: Date and time variables in SAS macro behaviour. Date works, time does not work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Date-and-time-variables-in-SAS-macro-behaviour-Date-works-time/m-p/236730#M14743</link>
      <description>&lt;P&gt;Hi mate, welcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've made a little change in your code and it worked as you said in the Log:&amp;nbsp;&lt;SPAN&gt;TheDate is 20408 and ThisDay is TODAY() and the diff is -11&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let TheDate= %sysfunc(datepart('16NOV2015:00:00:00'dt),best12.);
%Let ThisDay = %sysfunc(TODAY(),date9.);
%Put TheDate is &amp;amp;Dato and ThisDay is &amp;amp;Thisday and the diff is 
	%eval(%eval(%sysfunc(today(),best12.)) - %eval(&amp;amp;TheDate));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Hope this helps&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2015 14:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Date-and-time-variables-in-SAS-macro-behaviour-Date-works-time/m-p/236730#M14743</guid>
      <dc:creator>DartRodrigo</dc:creator>
      <dc:date>2015-11-27T14:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Date and time variables in SAS macro behaviour. Date works, time does not work</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Date-and-time-variables-in-SAS-macro-behaviour-Date-works-time/m-p/236920#M14749</link>
      <description>&lt;P&gt;Thank you very much for helping me understand this issue.&lt;/P&gt;&lt;P&gt;It was the floating point returned by %sysfunc(&amp;amp;ThisTime) that confused me. It could not be resolved by the %eval since this only handles integers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Let TheDate= %Sysevalf('29NOV2015'd);&lt;BR /&gt;%Let ThisDay = TODAY();&lt;BR /&gt;%Put TheDate is &amp;amp;TheDate and ThisDay is &amp;amp;ThisDay and the diff is %EvAL((&amp;amp;TheDate) - %SYSFUNC(&amp;amp;ThisDay));&lt;BR /&gt;&lt;BR /&gt;%Let TheTime = %Sysevalf('23:49:02't);&lt;BR /&gt;%Let ThisTime = Time();&lt;BR /&gt;%Put TheTime is &amp;amp;TheTime and ThisTime is &amp;amp;ThisTime or %SYSFUNC(&amp;amp;ThisTime) and the diff is %SYSEVALF(%SYSEVALF(&amp;amp;TheTime) - %sysfunc(&amp;amp;ThisTime));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2015 11:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Date-and-time-variables-in-SAS-macro-behaviour-Date-works-time/m-p/236920#M14749</guid>
      <dc:creator>sveinola_gundhus_tv2_no</dc:creator>
      <dc:date>2015-11-30T11:44:26Z</dc:date>
    </item>
  </channel>
</rss>

