The
macro facility is a string handling facility. However, in specific
situations, the macro processor can evaluate operands that represent
numbers as numeric values. When the macro processor evaluates an expression
that contains an arithmetic operator and operands that represent numbers,
it temporarily converts the operands to numeric values and performs
the integer arithmetic operation. The result of the evaluation is
text.
By default, arithmetic
evaluation in most macro statements and functions is performed with
integer arithmetic. The exception is the %SYSEVALF function. See
Evaluating Floating-Point Operands for more information. The following macro statements illustrate
integer arithmetic evaluation:
%let a=%eval(1+2);
%let b=%eval(10*3);
%let c=%eval(4/2);
%let i=%eval(5/3);
%put The value of a is &a;
%put The value of b is &b;
%put The value of c is &c;
%put The value of I is &i;
When you submit these
statements, the following messages appear in the log:
The value of a is 3
The value of b is 30
The value of c is 2
The value of I is 1
Notice the result of
the last statement. If you perform division on integers that would
ordinarily result in a fraction, integer arithmetic discards the fractional
part.
When the macro processor
evaluates an integer arithmetic expression that contains a character
operand, it generates an error. Only operands that contain characters
that represent integers or hexadecimal values are converted to numeric
values. The following statement shows an incorrect usage:
%let d=%eval(10.0+20.0); /*INCORRECT*/
Because the %EVAL function
supports only integer arithmetic, the macro processor does not convert
a value containing a period character to a number, and the operands
are evaluated as character operands. This statement produces the following
error message:
ERROR: A character operand was found in the %EVAL function or %IF
condition where a numeric operand is required. The condition was:
10.0+20.0