Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Language Reference

Comparison Operators:   <   >   =   <=   >=   ^=

compare matrix elements

matrix1<matrix2
matrix1<=matrix2
matrix1>matrix2
matrix1>=matrix2
matrix1=matrix2
matrix1^=matrix2

The comparison operators compare two matrices element by element and produce a new matrix that contains only zeros and ones. If an element comparison is true, the corresponding element of the new matrix is 1. If the comparison is not true, the corresponding element is 0. Unlike in base SAS software or the MATRIX procedure, you cannot use the English equivalents GT and LT for the greater than and less than signs. Scalar values can be used instead of matrices in any of the forms shown above.

For example, let

   a={1 7 3,
      6 2 4};
and
   b={0 8 2,
      4 1 3};
Evaluation of the expression
   c=a>b;
results in the matrix of values
              C             2 rows      3 cols    (numeric)

                              1         0         1
                              1         1         1

In addition to comparing conformable matrices, you can apply the comparison operators to a matrix and a scalar. If either argument is a scalar, the comparison is between each element of the matrix and the scalar.

For example the expression

   d=(a>=2);
yields the result
              D             2 rows      3 cols    (numeric)

                              0         1         1
                              1         1         1
If the element lengths of two character operands are different, the shorter elements are padded on the right with blanks for the comparison.

If a numeric missing value occurs in an operand, IML treats it as lower than any valid number for the comparison.

When you are making conditional comparisons, all values of the result must be nonzero for the condition to be evaluated as true.

Consider the following statement:

   if x>=y then goto loop1;
The GOTO statement is executed only if every element of x is greater than or equal to the corresponding element in y. See also the descriptions of the ALL and ANY functions.

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

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