This code works:
%let datetime_start = %Sysfunc( InputN( 05MAR2017:23:59:12 , DateTime18. ) ) ;
%let datetime_end = %Sysfunc( InputN( 06MAR2017:00:01:31 , DateTime18. ) ) ;
%let Duration = %sysfunc(putn(%sysevalf(&datetime_end-&datetime_start.),mmss.)) (mm:ss) ;
%put PROCESSING TIME: %sysfunc(putn(%sysevalf(&datetime_end-&datetime_start.),mmss.)) (mm:ss) ;
However, when I change to datetime(), it fails.
%let datetime_start = %sysfunc(DATETIME(),Datetime18.) ;
%put &datetime_start;
%let datetime_end = %sysfunc(DATETIME(),Datetime18.) ;
%put &datetime_end;
%let Duration = %sysfunc(putn(%sysevalf(&datetime_end-&datetime_start.),mmss.)) (mm:ss) ;
%put PROCESSING TIME: %sysfunc(putn(%sysevalf(&datetime_end-&datetime_start.),mmss.)) (mm:ss) ;
Errors:
1 %let datetime_start = %Sysfunc( InputN( 05MAR2017:23:59:12 , DateTime18. ) ) ;
2 %let datetime_end = %Sysfunc( InputN( 06MAR2017:00:01:31 , DateTime18. ) ) ;
3 %let Duration = %sysfunc(putn(%sysevalf(&datetime_end-&datetime_start.),mmss.)) (mm:ss) ;
4 %put PROCESSING TIME: %sysfunc(putn(%sysevalf(&datetime_end-&datetime_start.),mmss.)) (mm:ss) ;
PROCESSING TIME: 2:19 (mm:ss)
5 %let datetime_start = %sysfunc(DATETIME(),Datetime18.) ;
6 %put &datetime_start;
06MAR17:14:19:53
7 %let datetime_end = %sysfunc(DATETIME(),Datetime18.) ;
8 %put &datetime_end;
06MAR17:14:19:53
9 %let Duration = %sysfunc(putn(%sysevalf(&datetime_end-&datetime_start.),mmss.)) (mm:ss) ;
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
06MAR17:14:19:53-06MAR17:14:19:53
ERROR: %SYSEVALF function has no expression to evaluate.
ERROR: Argument 1 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC or
%QSYSFUNC function reference is terminated.
10 %put PROCESSING TIME: %sysfunc(putn(%sysevalf(&datetime_end-&datetime_start.),mmss.)) (mm:ss) ;
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
06MAR17:14:19:53-06MAR17:14:19:53
ERROR: %SYSEVALF function has no expression to evaluate.
ERROR: Argument 1 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC or
%QSYSFUNC function reference is terminated.
PROCESSING TIME: (mm:ss)
Remove the datetime18 formats. That's creating character variables, but if you leave it as numbers it will work fine.
%let datetime_start = %sysfunc(DATETIME()) ;
%put &datetime_start;
%let datetime_end = %sysfunc(DATETIME()) ;
%put &datetime_end;
%let Duration = %sysevalf(&datetime_end - &datetime_start); ;
%put &duration; ;
See above, unformatted final answer.
PS. When including code, especially longer code please use a code block { i } to format the code.
Remove the datetime18 formats. That's creating character variables, but if you leave it as numbers it will work fine.
%let datetime_start = %sysfunc(DATETIME()) ;
%put &datetime_start;
%let datetime_end = %sysfunc(DATETIME()) ;
%put &datetime_end;
%let Duration = %sysevalf(&datetime_end - &datetime_start); ;
%put &duration; ;
See above, unformatted final answer.
PS. When including code, especially longer code please use a code block { i } to format the code.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.