SAS Component Language: Reference

# Operators

 Arithmetic Operators

Symbol Definition
/ 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.

### Colon Modifier

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

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';
The code produces these messages:
```pen found

### IN Operator

`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 )
The elements of the comparison are

expression
can be any valid SAS expression, but it is usually a variable name when used with the IN operator.

value
must be a SAS constant. Value can be an array of constants.

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.

### AND Operator

```if 16<=age and age<=65;
if 16<=age<=65;```

### OR Operator

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;```