Precedence of operations

Expressions within parentheses are evaluated first. When the order of evaluation is not specified by parentheses, exponentiation is applied after prefix operators (such as -, unary minus) and before multiplication and division. Multiplication and division are applied before addition and subtraction. Operators at the same precedence level are applied from left to right.

The following table shows the priority of all operators.

Priority Operators
1 +, - (when used for signed numeric values)
2 **
3 *, /, CONCAT, ||
4 +, - (when used between two operands)

Example 1:

In this example, the first operation is the addition in (SALARY + BONUS) because it is within parenthesis. The second operation is multiplication because it is at a higher precedence level than the second addition operator and it is to the left of the division operator. The third operation is division because it is at a higher precedence level than the second addition operator. Finally, the remaining addition is performed.

          1.10 * (SALARY + BONUS) + SALARY / :VAR3
               ↑         ↑        ↑        ↑
              ┌┴┐       ┌┴┐      ┌┴┐      ┌┴┐
              │2│       │1│      │4│      │3│
              └─┘       └─┘      └─┘      └─┘

Example 2:

In this example, the first operation (CONCAT) combines the character strings in the variables YYYYMM and DD into a string representing a date. The second operation (-) then subtracts that date from the date being processed in DATECOL. The result is a date duration that indicates the time elapsed between the two dates.

          DATECOL - :YYYYMM CONCAT :DD
                  ↑           ↑
                 ┌┴┐         ┌┴┐
                 │2│         │1│
                 └─┘         └─┘