Search notes:

SAS programming - macro function: %eval

Integer arithmetic

%eval is only capable of integer arithmetic. For floating point arithmetic, %sysevalf must be used:
/*
   The %eval macro function can only evaluate integer
   arithmetic or logical expressions
*/

%put 39 + 3 = %eval( 39 + 3 );
%put 45 - 3 = %eval( 45 - 3 );

%let  one_plus_one = 1+1;
%put &one_plus_one; /* 1+1 */

%let two = %eval(&one_plus_one);
%put &two; /* 2 */

/* Eval can not handle floating point numbers.
   The following line causes
     ERROR: A character operand was found in the
     %EVAL function or %IF condition where a
     numeric operand is required.
*/
%put 45.1 - 3.1 = %eval( 45.1 - 3.1 );

/* %sysevalf however CAN evaluate floating point
   numbers: */
%put 45.1 - 3.1 = %sysevalf( 45.1 - 3.1 );  /* 45.1 - 3.1 = 42 */
%put 45   - 3   = %sysevalf( 45   - 3   );  /* 45   - 3   = 42 */
Github repository about-SAS, path: /macro-processor/functions/eval/integer-arithmetic.sas
The %if statement uses %eval to evaluate its condition. So, also an %if statement is incapable to perform something like %if 6.3 + 2.1 > 4.9 (See here).

See also

macro functions

Index