The %EVAL function evaluates
integer arithmetic or logical expressions. %EVAL operates by converting
its argument from a character value to a numeric or logical expression.
Then, it performs the evaluation. Finally, %EVAL converts the result
back to a character value and returns that value.
If all operands can
be interpreted as integers, the expression is treated as arithmetic.
If at least one operand cannot be interpreted as numeric, the expression
is treated as logical. If a division operation results in a fraction,
the fraction is truncated to an integer.
Logical, or Boolean,
expressions return a value that is evaluated as true or false. In
the macro language, any numeric value other than 0 is true and a value
of 0 is false.
%EVAL accepts only operands
in arithmetic expressions that represent integers (in standard or
hexadecimal form). Operands that contain a period character cause
an error when they are part of an integer arithmetic expression. The
following examples show correct and incorrect usage, respectively:
%let d=%eval(10+20); /* Correct usage */
%let d=%eval(10.0+20.0); /* Incorrect usage */
Because %EVAL does not
convert a value containing a period to a number, the operands are
evaluated as character operands. When %EVAL encounters a value containing
a period, it displays an error message about finding a character operand
where a numeric operand is required.
An expression that compares
character values in the %EVAL function uses the sort sequence of the
operating environment for the comparison. Refer to “The SORT
PROCEDURE” in the
Base SAS Procedures Guide for more
information about operating environment sort sequences.
All parts of the macro
language that evaluate expressions (for example, %IF and %DO statements)
call %EVAL to evaluate the condition. For a complete discussion of
how macro expressions are evaluated, see
Macro Expressions.