Symbol
Mnemonic
Equivalent Definition Example
IN equal to one from a list of
values
where state in
('NC','TX');
When you do character comparisons, you can use the colon (:) modifier to compare only
a specified prefix of a character string. For example, in the following WHERE
expression, the colon modifier, used after the equal sign, tells SAS to look at only the
first character in the values for variable LastName and to select the observations with
names beginning with the letter S:
where lastname=: 'S';
Note that in the SQL procedure, the colon modifier that is used in conjunction with an
operator is not supported; you can use the LIKE operator instead.
IN Operator
The IN operator, which is a comparison operator, searches for character and numeric
values that are equal to one from a list of values. The list of values must be in
parentheses, with each character value in quotation marks and separated by either a
comma or blank.
For example, suppose you want all sites that are in North Carolina or Texas. You could
specify:
where state = 'NC' or state = 'TX';
However, it is easier to use the IN operator, which selects any state in the list:
where state in ('NC','TX');
In addition, you can use the NOT logical operator to exclude a list.
where state not in ('CA', 'TN', 'MA');
You can use a shorthand notation to specify a range of sequential integers to search. The
range is specified by using the syntax M:N as a value in the list to search, where M is the
lower bound and N is the upper bound. M and N must be integers, and M, N, and all the
integers between M and N are included in the range. For example, the following
statements are equivalent.
• y = x in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
• y = x in (1:10);
Fully Bounded Range Condition
A fully bounded range condition consists of a variable between two comparison
operators, specifying both an upper and lower limit. For example, the following
expression returns the employee numbers that fall within the range of 500 to 1000
(inclusive):
where 500 <= empnum <= 1000;
Note that the previous range condition expression is equivalent to the following:
where empnum >= 500 and empnum <= 1000;
You can combine the NOT logical operator with a fully bounded range condition to
select observations that fall outside the range. Note that parentheses are required:
where not (500 <= empnum <= 1000);
Syntax of WHERE Expression 183