Arithmetic Expressions Logical Expressions
4 * 3 A < a
4 / 2 1 < &INDEX
00FFx - 003Ax &START NE &END
Defining Arithmetic and Logical Expressions
Evaluating Arithmetic and Logical Expressions
You can use arithmetic and logical expressions in specific macro functions and
statements. (See the following table.) The arithmetic and logical expressions in these
functions and statements enable you to control the text generated by a macro when it is
executed.
Table 6.2 Macro Language Elements That Evaluate Arithmetic and Logical Expressions
%DOmacro-variable=expression %TO expression<%BY expression>;
%DO %UNTIL(expression);
%DO %WHILE(expression);
%EVAL (expression);
%IF expression %THEN statement;
%QSCAN(argument,expression<,delimiters>)
%QSUBSTR(argument,expression<,expression>)
%SCAN(argument,expression,<delimiters>)
%SUBSTR(argument,expression<,expression>)
%SYSEVALF(expression,conversion-type)
You can use text expressions to generate partial or complete arithmetic or logical
expressions. The macro processor resolves text expressions before it evaluates the
arithmetic or logical expressions. For example, when you submit the following
statements, the macro processor resolves the macro variables &A, &B, and
&OPERATOR in the %EVAL function, before it evaluates the expression 2 + 5:
%let A=2;
%let B=5;
%let operator=+;
74 Chapter 6 Macro Expressions
%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
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset