<?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: %eval and %sysfunc operand error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/eval-and-sysfunc-operand-error/m-p/917293#M361330</link>
    <description>&lt;P&gt;Below should do what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _sdtm = %sysfunc(datetime());
data _null_;
  call sleep(2,1);
run;
%let _edtm = %sysfunc(datetime());

%let _runtm = %sysfunc(sum(&amp;amp;_edtm,-&amp;amp;_sdtm),time14.3);

%put The code took &amp;amp;_runtm to work;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The %eval() function is for integers but you're dealing with strings that represent floating point numbers for which you need to use %sysevalf().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _runtm2 = %sysfunc(putn(%sysevalf(&amp;amp;_edtm - &amp;amp;_sdtm),time14.3));
%put The code took &amp;amp;_runtm2 to work;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Most of the time using %sysfunc() is preferable because it gives you access to SAS functions and also lets you define the output format within the same function call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code returned an error because you tried to pack multiple operations (putn, subtraction) into a single %sysfunc() call. Additionally as the name %sysfunc() implies its for calling functions. If you want to subtract values you need to do it via a function call: %sysfunc(sum(var1,-var2))&lt;/P&gt;</description>
    <pubDate>Thu, 22 Feb 2024 02:08:18 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2024-02-22T02:08:18Z</dc:date>
    <item>
      <title>%eval and %sysfunc operand error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/eval-and-sysfunc-operand-error/m-p/917292#M361329</link>
      <description>&lt;P&gt;I keep getting the following error:&amp;nbsp;&amp;nbsp;ERROR: A character operand was found in the %EVAL function or&amp;nbsp;%IF condition where a numeric operand is required. The condition was: 234982340.88/60&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code below.&lt;/P&gt;&lt;P&gt;*Start SAS timer;&lt;BR /&gt;%let _sdtm = %sysfunc(datetime());&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;***LOTS OF CODE***;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*End SAS timer;&lt;BR /&gt;%let _edtm = %sysfunc(datetime());&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Show runtime;&lt;BR /&gt;%let _runtm = %eval(%sysfunc(putn(&amp;amp;_edtm - &amp;amp;_sdtm, 12.4))/60);&lt;BR /&gt;%put The code took &amp;amp;_runtm to work;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 01:38:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/eval-and-sysfunc-operand-error/m-p/917292#M361329</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-02-22T01:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: %eval and %sysfunc operand error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/eval-and-sysfunc-operand-error/m-p/917293#M361330</link>
      <description>&lt;P&gt;Below should do what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _sdtm = %sysfunc(datetime());
data _null_;
  call sleep(2,1);
run;
%let _edtm = %sysfunc(datetime());

%let _runtm = %sysfunc(sum(&amp;amp;_edtm,-&amp;amp;_sdtm),time14.3);

%put The code took &amp;amp;_runtm to work;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The %eval() function is for integers but you're dealing with strings that represent floating point numbers for which you need to use %sysevalf().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _runtm2 = %sysfunc(putn(%sysevalf(&amp;amp;_edtm - &amp;amp;_sdtm),time14.3));
%put The code took &amp;amp;_runtm2 to work;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Most of the time using %sysfunc() is preferable because it gives you access to SAS functions and also lets you define the output format within the same function call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code returned an error because you tried to pack multiple operations (putn, subtraction) into a single %sysfunc() call. Additionally as the name %sysfunc() implies its for calling functions. If you want to subtract values you need to do it via a function call: %sysfunc(sum(var1,-var2))&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 02:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/eval-and-sysfunc-operand-error/m-p/917293#M361330</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-02-22T02:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: %eval and %sysfunc operand error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/eval-and-sysfunc-operand-error/m-p/917297#M361333</link>
      <description>&lt;P&gt;Thank you for your thoughtful explanation. I suspected I was dealing with a string vs. integer vs. float issue, but I am new to using SAS and couldn't figure out the syntax to make this work. Your response was supremely helpful. Cheers.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2024 03:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/eval-and-sysfunc-operand-error/m-p/917297#M361333</guid>
      <dc:creator>sas_user_1001</dc:creator>
      <dc:date>2024-02-22T03:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: %eval and %sysfunc operand error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/eval-and-sysfunc-operand-error/m-p/917303#M361334</link>
      <description>&lt;P&gt;You need %SYSEVALF() to do floating point arithmetic in MACRO code.&amp;nbsp; %EVAL() only does integer arithmetic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you don't need to call SUM() to do arithmetic (unless you want missing values to be treated as zero).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;63   %let sdtm = "&amp;amp;sysdate9:&amp;amp;systime"dt;
64   %let edtm = %sysfunc(datetime());
65   %let minutes = %sysevalf((&amp;amp;edtm - &amp;amp;sdtm)/60);
66   %put Code took &amp;amp;=minutes ;
Code took MINUTES=813.0412833333
&lt;/PRE&gt;
&lt;P&gt;There is a good macro for timing already:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/bench.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/bench.sas&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro bench
/*----------------------------------------------------------------------
Measures elapsed time (in seconds) between sucessive invocations
----------------------------------------------------------------------*/
(mvar /* Macro variable used for recording start time (default=_bench)*/
);
/*----------------------------------------------------------------------
Call it once to start the timing and then a second time to report the
elapsed time and clear the saved time.

Use different values for MVAR to time multiple overlapping periods.
----------------------------------------------------------------------*/
%if (&amp;amp;mvar=) %then %let mvar=_bench;
%if ^%symexist(&amp;amp;mvar) %then %global &amp;amp;mvar;

%if (&amp;amp;&amp;amp;&amp;amp;mvar =) %then %let &amp;amp;mvar = %sysfunc(datetime());
%else %do;
  %put NOTE: Elapsed seconds = %sysevalf(%sysfunc(datetime()) - &amp;amp;&amp;amp;&amp;amp;mvar);
  %let &amp;amp;mvar =;
%end;
%mend bench;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Feb 2024 05:46:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/eval-and-sysfunc-operand-error/m-p/917303#M361334</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-22T05:46:26Z</dc:date>
    </item>
  </channel>
</rss>

