## Elementwise Binary Operators

Elementwise binary operators produce a result matrix from
element-by-element operations on two argument matrices.
Table 4.2 lists the elementwise binary operators.

**Table 4.2:** Elementwise Binary Operators
**Operator** | | **Action** |

+ | | addition, concatenation |

- | | subtraction |

# | | elementwise multiplication |

## | | elementwise power |

/ | | division |

<> | | element maximum |

>< | | element minimum |

| | | logical OR |

& | | logical AND |

< | | less than |

<= | | less than or equal to |

> | | greater than |

>= | | greater than or equal to |

^= | | not equal to |

= | | equal to |

MOD(*m*,*n*) | | modulo (remainder) |

For example, consider the following two matrices
**A** and **B** given below.

The addition operator (+) adds corresponding matrix elements:

The elementwise multiplication operator
(#) multiplies corresponding elements:

The elementwise power operator (##) raises elements to powers:

The element maximum operator (<>) compares
corresponding elements and chooses the larger:

The less than or equal to operator (<=) returns a 1
if an element of **A** is less than or equal to the
corresponding element of **B**, and returns a 0 otherwise:

The modulo operator returns the remainder
of each element divided by the argument:

All operators can also work in a one-to-many or many-to-one
manner, as well as in an element-to-element manner;
that is, they enable you to perform tasks such as adding
a scalar to a matrix or dividing a matrix by a scalar.
For example, the statement

x=x#(x>0);

replaces each negative element of the matrix **X** with 0.
The expression (X>0) is a many-to-one operation that
compares each element of **X** to 0 and creates a
temporary matrix of results; an element in the result matrix
is 1 when the expression is true and 0 when it is false.
When the expression is true (the element is
positive), the element is multiplied by 1.
When the expression is false (the element is
negative or 0), the element is multiplied by 0.
To fully understand the intermediate calculations,
you can use the RESET: PRINTALL command to
have the temporary result matrices displayed.

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