Working with Matrices
Compound Expressions
With SAS/IML software, you can write compound expressions that involve several matrix operators and operands. For example, the following statements are valid matrix assignment statements:
a = x+y+z;
a = x+y*z`;
a = (-x)#(y-z);
The rules for evaluating compound expressions are as follows:
-
Evaluation follows the order of operator precedence, as described in Table 1. Group I has the highest priority; that is, Group I operators are evaluated first. Group II operators are evaluated after Group I operators, and so forth. Consider the following statement:
a = x+y*z;This statement first multiplies matrices
yandzsince the * operator (Group II) has higher precedence than the + operator (Group III). It then adds the result of this multiplication to the matrixxand assigns the new matrix toa. -
If neighboring operators in an expression have equal precedence, the expression is evaluated from left to right, except for the Group I operators. Consider the following statement:
a = x/y/z;This statement first divides each element of matrix
xby the corresponding element of matrixy. Then, using the result of this division, it divides each element of the resulting matrix by the corresponding element of matrixz. The operators in Group I, described in Table 1, are evaluated from right to left. For example, the following expression is evaluated as:
-x**2When multiple prefix or postfix operators are juxtaposed, precedence is determined by their order from inside to outside.
For example, the following expression is evaluated as
:
a`[i,j] -
All expressions enclosed in parentheses are evaluated first, using the two preceding rules. Consider the following statement:
a = x/(y/z);This statement is evaluated by first dividing elements of
yby the elements ofz, then dividing this result intox.