MIN and MAX Operators
Use the MIN or MAX operators to find the minimum or maximum value of two
quantities. Surround the operators with the two quantities whose minimum or maximum
value you want to know.
The MIN operator returns the lower of the two values.
The MAX operator returns the higher of two values.
For example, if A is less than B, then the following would return the value of A:
where x = (a min b);
Note: The symbol representation >< is not supported, and <> is interpreted as “not equal
to.”
Concatenation Operator
The concatenation operator concatenates character values. You indicate the
concatenation operator as follows:
|| (two OR symbols)
!! (two exclamation marks)
¦¦ (two broken vertical bars).
For example:
where name = 'John'||'Smith';
Prefix Operators
The plus sign (+) and minus sign (–) can be either prefix operators or arithmetic
operators. They are prefix operators when they appear at the beginning of an expression
or immediately preceding an open parenthesis. A prefix operator is applied to the
variable, constant, SAS function, or parenthetic expression.
where z = −(x + y);
Note: The NOT operator is also considered a prefix operator.
Combining Expressions By Using Logical
Operators
Syntax
You can combine or modify WHERE expressions by using the logical operators (also
called Boolean operators) AND, OR, and NOT. The basic syntax of a compound
WHERE expression is as follows:
WHERE where-expression-1 AND | OR | NOT where-expression-n
AND combines two conditions by finding observations that satisfy both conditions. For
example:
where skill eq 'java' and years eq 4;
OR combines two conditions by finding observations that satisfy either condition or
both. For example:
188 Chapter 11 WHERE-Expression Processing
where skill eq 'java' or years eq 4;
NOT modifies a condition by finding the complement of the specified criteria. You can
use the NOT logical operator in combination with any SAS and WHERE expression
operator. And you can combine the NOT operator with AND and OR. For example:
where skill not eq 'java' or years not eq 4;
The logical operators and their equivalent symbols are shown in the following table:
Table 11.4 Logical (Boolean) Operators
Symbol Mnemonic Equivalent
& AND
! or | or ¦ OR
^ or ~ or ¬ NOT
Processing Compound Expressions
When SAS encounters a compound WHERE expression (multiple conditions), the
software follows rules to determine the order in which to evaluate each expression.
When WHERE expressions are combined, SAS processes the conditions in a specific
order:
1. The NOT expression is processed first.
2. Then the expressions joined by AND are processed.
3. Finally, the expressions joined by OR are processed.
Using Parentheses to Control Order of Evaluation
Even though SAS evaluates logical operators in a specific order, you can control the
order of evaluation by nesting expressions in parentheses. That is, an expression
enclosed in parentheses is processed before one not enclosed. The expression within the
innermost set of parentheses is processed first, followed by the next deepest, moving
outward until all parentheses have been processed.
For example, suppose you want a list of all the Canadian sites that have both
SAS/GRAPH and SAS/STAT software, so you issue the following expression:
where product='GRAPH' or product='STAT' and country='Canada';
The result, however, includes all sites that license SAS/GRAPH software along with the
Canadian sites that license SAS/STAT software. To obtain the correct results, you can
use parentheses, which causes SAS to evaluate the comparisons within the parentheses
first, providing a list of sites with either product licenses, then the result is used for the
remaining condition:
where (product='GRAPH' or product='STAT') and country='Canada';
Combining Expressions By Using Logical Operators 189

Get SAS 9.4 Language Reference, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.