%put The result of &A &operator &B is %eval(&A &operator
&B).;
When you submit these statements, the %PUT statement writes the following to the log:
The result of 2 + 5 is 7.
Operands and Operators
Operands in arithmetic or logical expressions are always text. However, an operand that
represents a number can be temporarily converted to a numeric value when an
expression is evaluated. By default, the macro processor uses integer arithmetic, and
only integers and hexadecimal values that represent integers can be converted to a
numeric value. Operands that contain a period character (for example 1.0) are not
converted. The exception is the %SYSEVALF function. It interprets a period character in
its argument as a decimal point and converts the operand to a floating-point value on
your operating system.
Note: The values of numeric expressions are restricted to the range of –2**64 to 2**64–
1.
Operators in macro expressions are a subset of the operators in the DATA step (Table
6.3 on page 75). However, in the macro language, there is no MAX or MIN operator,
and it does not recognize ':', as does the DATA step. The order in which operations are
performed when an expression is evaluated is the same in the macro language as in the
DATA step. Operations within parentheses are performed first.
Note: Expressions in which comparison operators surround a macro expression, as in
10<&X<20, might be the equivalent of a DATA step compound expression
(depending on the expression resolution). To be safe, specify the connecting
operator, as in the expression 10<&X AND &X<20.
Note: Datetime constants are internally converted using the BEST12. format.
Table 6.3 Macro Language Operators
Operator Mnemonic Precedence Definition Example
** 1 exponentiation 2**4
+ 2 positive prefix +(A+B)
- 2 negative
prefix
-(A+B)
¬^~ NOT 3 logical not* NOT A
* 4 multiplication A*B
/ 4 division A/B
+ 5 addition A+B
- 5 subtraction A-B
< LT 6 less than A<B
<= LE 6 less than or
equal
A<=B
Defining Arithmetic and Logical Expressions 75