![]() Chapter Contents |
![]() Previous |
![]() Next |
| SAS Component Language: Reference |
| Arithmetic Operators |
| Symbol | Definition |
|---|---|
| + | addition |
| / | division |
| ** | exponentiation |
| * | multiplication |
| - | subtraction |
| Comparison Operators |
| Symbol |
Mnemonic Equivalent |
Definition |
|---|---|---|
| = | EQ | equal to |
| ^= * | NE | not equal to |
| ¬= * | NE | not equal to |
| > | GT | greater than |
| < | LT | less than |
| >= ** | GE | greater than or equal to |
| <= ** | LE | less than or equal to |
| <> |
|
maximum |
| >< |
|
minimum |
| || | concatenation | |
| IN | equal to one item in a list | |
| *The symbol that you use for NE depends on your
keyboard.
**The symbols =< and => are also accepted for compatibility with previous releases of SAS. |
||
You can add a colon (:) modifier after any operator
to compare only a specified prefix of a character string. For example, the
following code produces the message
pen found, because the string
pen occurs at the beginning (as a prefix) of
pencil:
var='pen'; if var =: 'pencil' then put var 'found'; else put var 'not found';
The following code produces the message
phone not found because
phone occurs at the end (as a suffix) of
telephone:
var='phone'; if var =: 'telephone'; then put var 'found'; else put var 'not found';The code produces these messages:
pen found phone not found
if age in (16, 21, 25);The result is 1 if the value on the left matches a value in the list. Otherwise, the result is 0. The form of the comparison is
| expression IN <value-1<, . . . ,value-n>) |
| Logical (Boolean) Operators |
| Symbol |
Mnemonic Equivalent |
Definition |
|---|---|---|
| & | AND | AND comparison |
| | | OR | OR comparison |
| ¬ * | NOT | NOT comparison |
| ^ * | NOT | NOT comparison |
| ~ * | NOT | NOT comparison |
| *The symbol that you use for NOT depends on your keyboard. | ||
if 16<=age and age<=65; if 16<=age<=65;
If either condition compared by an OR operator is true, then the result of the OR operation is true.
if x=1 or 2;Although X=1 may be either true or false, the 2 is evaluated as nonzero and nonmissing, so the entire expression is true. In the following statement, however, the condition is not necessarily true, because either comparison can evaluate as true or false:
if x=1 or x=2;You can also use the IN operator with a series of comparisons. The following statements are equivalent:
if x in (2, 4, 6); if x=2 or x=4 or x=6;
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.