Pattern Name Selected
like 'D_an%' all names from list
You can use a SAS character expression to specify a pattern, but you cannot use a SAS
character expression that uses a SAS function.
You can combine the NOT logical operator with LIKE to select values that do not have
the specified pattern, such as the following:
where frstname not like 'D_an%';
Because the % and _ characters have special meaning for the LIKE operator, you must
use an escape character when searching for the % and _ characters in values. An escape
character is a single character that, in a sequence of characters, signifies that what
follows takes an alternative meaning. For the LIKE operator, an escape character
signifies to search for literal instances of the % and _ characters in the variable's values
instead of performing the special-character function.
For example, if the variable X contains the values abc, a_b, and axb, the following
LIKE operator with an escape character selects only the value
a_b. The escape character
(/) specifies that the pattern searches for a literal ' _' that is surrounded by the characters
a and b. The escape character (/) is not part of the search.
where x like 'a/_b' escape '/';
Without an escape character, the following LIKE operator would select the values a_b
and axb. The special character underscore in the search pattern matches any single b
character, including the value with the underscore:
where x like 'a_b';
To specify an escape character, include the character in the pattern-matching expression,
and then the keyword ESCAPE followed by the escape-character expression. When you
include an escape character, the pattern-matching expression must be enclosed in
quotation marks, and it cannot contain a column name. The escape-character expression
evaluates to a single character. The operands must be character or string literals. If it is a
single character, enclose it in quotation marks.
LIKE 'pattern-matching-expression' ESCAPE 'escape-character-expression'
Sounds-like Operator
The sounds-like ( =*) operator selects observations that contain a spelling variation of a
specified word or words. The operator uses the Soundex algorithm to compare the
variable value and the operand. For more information, see the SOUNDEX function in
SAS Functions and CALL Routines: Reference.
Note: Note that the SOUNDEX algorithm is English-biased, and is less useful for
languages other than English.
Although the sounds-like operator is useful, it does not always select all possible values.
For example, consider that you want to select observations from the following list of
names that sound like Smith:
• Schmitt
• Smith
• Smithson
• Smitt
186 Chapter 11 • WHERE-Expression Processing