Chapter Contents |
Previous |
Next |

Working with Matrices |

With SAS/IML software, you can write compound expressions involving several matrix operators and operands. For example, the following statements are valid matrix assignment statements:

a=x+y+z; a=x+y*z\prime ; a=(-x)#(y-z);

The rules for evaluating compound expressions are as follows:

- Evaluation follows the order of operator
precedence, as shown in Table 4.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.
For example, the statement
a=x+y*z;

first multiplies matrices**Y**and**Z**since the * operator (Group II) has higher precedence than the + operator (Group III). It then adds the result of this multiplication to the matrix**X**and assigns the new matrix to**A**. - If neighboring operators in an expression have equal
precedence, the expression is evaluated from left
to right, except for the highest priority operators.
For example, the statement
a=x/y/z;

first divides each element of matrix**X**by the corresponding element of matrix**Y**. Then, using the result of this division, it divides each element of the resulting matrix by the corresponding element of matrix**Z**. The operators in Group 1 in Table 4.1 are evaluated from right to left. For example, the expression-x**2

is evaluated as-(x**2)

When multiple prefix or postfix operators are juxtaposed, precedence is determined by their order from inside to outside.For example, the expression

^-a

is evaluated as ^(-**A**), and the expressiona`[i,j]

is evaluated as . - All expressions enclosed in parentheses are
evaluated first, using the two preceding rules.
Thus, the IML statement
a=x/(y/z);

is evaluated by first dividing elements of**Y**by the elements of**Z**, then dividing this result into**X**.

Chapter Contents |
Previous |
Next |
Top |

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.