<?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: Calculate length of time job runs-over midnight in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338522#M77104</link>
    <description>Thank you for quick response!</description>
    <pubDate>Mon, 06 Mar 2017 18:25:46 GMT</pubDate>
    <dc:creator>labin</dc:creator>
    <dc:date>2017-03-06T18:25:46Z</dc:date>
    <item>
      <title>Calculate length of time job runs-over midnight</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338513#M77096</link>
      <description>&lt;P&gt;%let End_Date_Time = %sysfunc(datetime());&lt;/P&gt;&lt;P&gt;%let Start_Date_Time = %sysfunc(datetime());&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put Duration = %sysfunc(putn(%sysevalf(&amp;amp;datetime_end.-&amp;amp;datetime_start.),mmss.)) (mm:ss) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is when this job starts before midnight and ends the next day. &amp;nbsp;I am getting &amp;nbsp;" -1437 (mm:ss)". &amp;nbsp;How do I get this to calculate the real minutes/seconds between the two dates. &amp;nbsp;See example date times.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let datetime_start = %Sysfunc( InputN( 05MAR2017:23:59:12 , DateTime14 ) ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %let datetime_end = %Sysfunc( InputN( 06MAR2017:00:01:31 , DateTime14 ) ) ;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 17:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338513#M77096</guid>
      <dc:creator>labin</dc:creator>
      <dc:date>2017-03-06T17:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate length of time job runs-over midnight</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338517#M77099</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think if you change your datatime format length , you should get the correct results using your existing code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a woking example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let datetime_start = %Sysfunc( InputN( 05MAR2017:23:59:12 , DateTime&lt;FONT color="#FF0000"&gt;18&lt;/FONT&gt;. ) ) ;&lt;BR /&gt;%let datetime_end = %Sysfunc( InputN( 06MAR2017:00:01:31 , DateTime&lt;FONT color="#FF0000"&gt;18&lt;/FONT&gt;. ) ) ;&lt;BR /&gt;&lt;BR /&gt;%put Duration = %sysfunc(putn(%sysevalf(&amp;amp;datetime_end.-&amp;amp;datetime_start.),mmss.)) (mm:ss) ; --&amp;gt; Duration =&amp;nbsp; 2:19 (mm:ss)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 18:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338517#M77099</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2017-03-06T18:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate length of time job runs-over midnight</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338520#M77102</link>
      <description>&lt;P&gt;Change line:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%put Duration = %sysfunc(putn(%sysevalf(&amp;amp;datetime_end.-&amp;amp;datetime_s&lt;/SPAN&gt;&lt;WBR /&gt;&lt;SPAN&gt;tart.),mmss.)) (mm:ss) ;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;To:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%put Duration = %sysfunc(putn(%sysevalf(&amp;amp;datetime_end.-&amp;amp;datetime_s&lt;WBR /&gt;tart.),&lt;STRONG&gt;time9.&lt;/STRONG&gt;)) (&lt;STRONG&gt;hh:mm:ss&lt;/STRONG&gt;) ;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 18:19:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338520#M77102</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-06T18:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate length of time job runs-over midnight</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338521#M77103</link>
      <description>&lt;P&gt;When I run:&lt;/P&gt;
&lt;PRE&gt;%let datetime_start = %Sysfunc( InputN( 05MAR2017:23:59:12 , DateTime14 ) ) ;

%let datetime_end = %Sysfunc( InputN( 06MAR2017:00:01:31 , DateTime14 ) ) ;

%put Duration= %sysfunc(putn(%sysevalf(&amp;amp;datetime_end.-&amp;amp;datetime_start.),mmss.)) (mm:ss) ;
&lt;/PRE&gt;
&lt;P&gt;Result is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Duration= 55:00 (mm:ss)&lt;/P&gt;
&lt;P&gt;To get a value like -1437 then the End has to be smaller than the start, i.e: your END value is &lt;STRONG&gt;before&lt;/STRONG&gt; the START..&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 18:23:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338521#M77103</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-06T18:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate length of time job runs-over midnight</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338522#M77104</link>
      <description>Thank you for quick response!</description>
      <pubDate>Mon, 06 Mar 2017 18:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338522#M77104</guid>
      <dc:creator>labin</dc:creator>
      <dc:date>2017-03-06T18:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate length of time job runs-over midnight</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338583#M77134</link>
      <description>&lt;P&gt;This code works:&lt;/P&gt;&lt;P&gt;%let datetime_start = %Sysfunc( InputN( 05MAR2017:23:59:12 , DateTime18. ) ) ;&lt;BR /&gt;%let datetime_end = %Sysfunc( InputN( 06MAR2017:00:01:31 , DateTime18. ) ) ;&lt;BR /&gt;%let Duration = %sysfunc(putn(%sysevalf(&amp;amp;datetime_end-&amp;amp;datetime_start.),mmss.)) (mm:ss) ;&lt;BR /&gt;%put PROCESSING TIME: %sysfunc(putn(%sysevalf(&amp;amp;datetime_end-&amp;amp;datetime_start.),mmss.)) (mm:ss) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I change to datetime(), it fails.&lt;/P&gt;&lt;P&gt;%let datetime_start = %sysfunc(DATETIME(),Datetime18.) ;&lt;BR /&gt;%put &amp;amp;datetime_start;&lt;BR /&gt;%let datetime_end = %sysfunc(DATETIME(),Datetime18.) ;&lt;BR /&gt;%put &amp;amp;datetime_end;&lt;BR /&gt;%let Duration = %sysfunc(putn(%sysevalf(&amp;amp;datetime_end-&amp;amp;datetime_start.),mmss.)) (mm:ss) ;&lt;BR /&gt;%put PROCESSING TIME: %sysfunc(putn(%sysevalf(&amp;amp;datetime_end-&amp;amp;datetime_start.),mmss.)) (mm:ss) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Errors:&lt;/P&gt;&lt;P&gt;1 %let datetime_start = %Sysfunc( InputN( 05MAR2017:23:59:12 , DateTime18. ) ) ;&lt;BR /&gt;2 %let datetime_end = %Sysfunc( InputN( 06MAR2017:00:01:31 , DateTime18. ) ) ;&lt;BR /&gt;3 %let Duration = %sysfunc(putn(%sysevalf(&amp;amp;datetime_end-&amp;amp;datetime_start.),mmss.)) (mm:ss) ;&lt;BR /&gt;4 %put PROCESSING TIME: %sysfunc(putn(%sysevalf(&amp;amp;datetime_end-&amp;amp;datetime_start.),mmss.)) (mm:ss) ;&lt;BR /&gt;PROCESSING TIME: 2:19 (mm:ss)&lt;BR /&gt;5 %let datetime_start = %sysfunc(DATETIME(),Datetime18.) ;&lt;BR /&gt;6 %put &amp;amp;datetime_start;&lt;BR /&gt;06MAR17:14:19:53&lt;BR /&gt;7 %let datetime_end = %sysfunc(DATETIME(),Datetime18.) ;&lt;BR /&gt;8 %put &amp;amp;datetime_end;&lt;BR /&gt;06MAR17:14:19:53&lt;BR /&gt;9 %let Duration = %sysfunc(putn(%sysevalf(&amp;amp;datetime_end-&amp;amp;datetime_start.),mmss.)) (mm:ss) ;&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&lt;BR /&gt;06MAR17:14:19:53-06MAR17:14:19:53&lt;BR /&gt;ERROR: %SYSEVALF function has no expression to evaluate.&lt;BR /&gt;ERROR: Argument 1 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.&lt;BR /&gt;ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC or&lt;BR /&gt;%QSYSFUNC function reference is terminated.&lt;BR /&gt;10 %put PROCESSING TIME: %sysfunc(putn(%sysevalf(&amp;amp;datetime_end-&amp;amp;datetime_start.),mmss.)) (mm:ss) ;&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&lt;BR /&gt;06MAR17:14:19:53-06MAR17:14:19:53&lt;BR /&gt;ERROR: %SYSEVALF function has no expression to evaluate.&lt;BR /&gt;ERROR: Argument 1 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.&lt;BR /&gt;ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC or&lt;BR /&gt;%QSYSFUNC function reference is terminated.&lt;BR /&gt;PROCESSING TIME: (mm:ss)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 21:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338583#M77134</guid>
      <dc:creator>labin</dc:creator>
      <dc:date>2017-03-06T21:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate length of time job runs-over midnight</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338595#M77137</link>
      <description>&lt;P&gt;You don't need to format the datetime_start and datetime_end macro variables. Keep them in their native numeric value, to avoid arythmetic operation errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You just need to format them at the end during Final/Summary phase.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You original formula worked, because you converted the datetime text value into a numeric value using the INPUTN function.&lt;/P&gt;
&lt;P&gt;Your second formula fails, because you are using text with ':' in a mathematical formula.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 21:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-length-of-time-job-runs-over-midnight/m-p/338595#M77137</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2017-03-06T21:47:47Z</dc:date>
    </item>
  </channel>
</rss>

