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);If the IN operator returns 0 if the value on the left does not match a value in the list. The result is 1 if the value on the left matches a value in the list. In the case of arrays, the IN operator returns the index of the element if it finds a match.
The form of the comparison is
expression IN <value-1<, . . . ,value-n>) |
Suppose you have the following program section:
init: declare a[5] = (2 4 6 8 10); b = 6; if b in a then put 'B is in array A'; c=b in a; put c=; return;This code produces the following output:
B in in array A c=3
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.
Be careful when using the OR operator with a series of comparisons (in an IF, SELECT, or WHERE statement, for example). Remember that only one comparison in a series of OR comparisons needs to be true in order to make a condition true. Also, any nonzero, nonmissing constant is always evaluated as true. Therefore, the following subsetting IF statement is always 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.