Boolean Numeric Expressions
In computing terms, a value of true is a 1 and a value of false is a 0. In SAS, any
numeric value other than 0 or missing is true, and a value of 0 or missing is false.
Therefore, a numeric variable or expression can stand alone in a condition. If its value is
a number other than 0 or missing, the condition is true. If its value is 0 or missing, the
condition is false.
0 | . = False
1 = True
For example, suppose that you want to fill in variable Remarks depending on whether
the value of Cost is present for a given observation. You can write the IF-THEN
statement as follows:
if cost then remarks='Ready to budget';
This statement is equivalent to:
if cost ne . and cost ne 0
then remarks='Ready to budget';
A numeric expression can be simply a numeric constant, as follows:
if 5 then do;
The numeric value that is returned by a function is also a valid numeric expression:
if index(address,'Avenue') then do;
The MIN and MAX Operators
The MIN and MAX operators are used 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 the two values. For example, if A<B, then
A><B returns the value of A.
If missing values are part of the comparison, SAS uses the sorting order for missing
values that is described in “Order of Missing Values” on page 85. For example, the
maximum value that is returned by .A<>.Z is the value .Z.
Note: In a WHERE statement or clause, the <> operator is equivalent to NE.
The Concatenation Operator
The concatenation operator (||) concatenates character values. The results of a
concatenation operation are usually stored in a variable with an assignment statement, as
in level='grade '||'A'. The length of the resulting variable is the sum of the
lengths of each variable or constant in the concatenation operation, unless you use a
LENGTH or ATTRIB statement to specify a different length for the new variable.
The concatenation operator does not trim leading or trailing blanks. If variables are
padded with trailing blanks, check the lengths of the variables and use the TRIM
function to trim trailing blanks from values before concatenating them. See SAS
Functions and CALL Routines: Reference for descriptions and examples of additional
character functions.
SAS Operators in Expressions 107