Chapter Contents


The SQL Procedure

LIKE condition

Tests for a matching pattern.

sql-expression <NOT> LIKE sql-expression

The LIKE condition selects rows by comparing character strings with a pattern-matching specification. It resolves to true and displays the matched string(s) if the left operand matches the pattern specified by the right operand.

Patterns for Searching
Patterns are composed of three classes of characters:

underscore (_)
matches any single character.

percent sign (%)
matches any sequence of zero or more characters.

any other character
matches that character.

These patterns can appear before, after, or on both sides of characters that you want to match. The LIKE condition is case-sensitive.

The following list uses these values: Smith, Smooth, Smothers, Smart, and Smuggle.

matches Smith, Smooth, Smothers, Smart, Smuggle.

matches Smith, Smooth.

matches Smuggle.

matches a three-letter word, so it has no matches here.

matches Smooth, Smothers.

matches Smith, Smooth.

matches the single, uppercase character Z only, so it has no matches here.

Searching for Mixed-Case Strings
To search for mixed-case strings, use the UPCASE function to make all the names uppercase before entering the LIKE condition:

   upcase(name) like 'SM%';

Note:   When you are using the % character, be aware of the effect of trailing blanks. You may have to use the TRIM function to remove trailing blanks in order to match values.  [cautionend]

Chapter Contents



Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.