SOUNDEX: Comparing Character Strings Phonetically

How to:

Available Languages: reporting, Maintain

The SOUNDEX function analyzes a character string phonetically, without regard to spelling. It converts character strings to four character codes. The first character must be the first character in the string. The last three characters represent the next three significant sounds in the source string.

To conduct a phonetic search, do the following:

  1. Use SOUNDEX to translate data values from the field you are searching for to the phonetic codes.
  2. Use SOUNDEX to translate your best guess target string to a phonetic code. Remember that the spelling of your target string need be only approximate. However, the first letter must be correct.
  3. Use WHERE or IF criteria to compare the temporary fields created in Step 1 to the temporary field created in Step 2.

Syntax: How to Compare Character Strings Phonetically

SOUNDEX(length, source_string, output)

where:

length

Alphanumeric

Is the number of characters in source_string, or a field that contains the length. It can be a number enclosed in single quotation marks, or a field containing the number. The number must be from 01 to 99, expressed with two digits (for example '01'); a number larger than 99 causes the function to return asterisks (*) as output.

source_string

Alphanumeric

Is the string to analyze enclosed in single quotation marks, or a field or variable that contains the character string.

output

Alphanumeric

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.

Example: Comparing Character Strings Phonetically

The following request creates three fields:

  • PHON_NAME contains the phonetic code of employee last names.
  • PHON_COY contains the phonetic code of your guess, MICOY.
  • PHON_MATCH contains YES if the phonetic codes match, NO if they do not.

The WHERE criteria selects the last name that matches your best guess.

DEFINE FILE EMPLOYEE
PHON_NAME/A4 = SOUNDEX('15', LAST_NAME, PHON_NAME);
PHON_COY/A4 WITH LAST_NAME = SOUNDEX('15', 'MICOY', PHON_COY);
PHON_MATCH/A3 = IF PHON_NAME IS PHON_COY THEN 'YES' ELSE 'NO';
END
TABLE FILE EMPLOYEE
PRINT LAST_NAME
IF PHON_MATCH IS 'YES'
END

The output is:

LAST_NAME
---------
MCCOY