%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*/
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
Evaluating Floating-Point Operands
The %SYSEVALF function evaluates arithmetic expressions with operands that
represent floating-point values. For example, the following expressions in the
%SYSEVALF function are evaluated using floating-point arithmetic:
%let a=%sysevalf(10.0*3.0);
%let b=%sysevalf(10.5+20.8);
%let c=%sysevalf(5/3);
%put 10.0*3.0 = &a;
%put 10.5+20.8 = &b;
%put 5/3 = &c;
The %PUT statements display the following messages in the log:
10.0*3.0 = 30
10.5+20.8 = 31.3
5/3 = 1.6666666667
When the %SYSEVALF function evaluates arithmetic expressions, it temporarily
converts the operands that represent numbers to floating-point values. The result of the
evaluation can represent a floating-point value, but as in integer arithmetic expressions,
the result is always text.
The %SYSEVALF function provides conversion type specifications: BOOLEAN,
INTEGER, CEIL, and FLOOR. For example, the following %PUT statements return 1,
2, 3, and 2 respectively:
%let a=2.5;
%put %sysevalf(&a,boolean);
%put %sysevalf(&a,integer);
%put %sysevalf(&a,ceil);
%put %sysevalf(&a,floor);
How the Macro Processor Evaluates Arithmetic Expressions 77