Selects a given word from a character expression
Category: Character
SCAN ( string ,n <, delimiter (s) >)
string
specifies any character expression.
n
specifies a numeric expression that produces the number of the word in the character string you want SCAN to select. The following rules apply:
If n is negative, SCAN selects the word in the character string starting from the end of the string.
If n is greater than the number of words in the character string, SCAN returns a blank value.
delimiter
specifies a character expression that produces characters that you want SCAN to use as a word separator in the character string.
Default: If you omit delimiter in an ASCII environment, SAS uses the following characters:
blank . < ( + & ! $ * ); ^ - / , %
In ASCII environments without the ^ character, SCAN uses the ~ character instead.
If you omit delimiter in an EBCDIC environment, SAS uses the following characters:
blank . < ( + & ! $ * ); -/,% ¢
Tip: If you represent delimiter as a constant, enclose delimiter in quotation marks.
If the SCAN function returns a value to a variable that has not yet been assigned a length, by default the variable is assigned a length of 200.
Leading delimiters before the first word in the character string do not effect SCAN. If there are two or more contiguous delimiters, SCAN treats them as one.
| SAS Statements | Results |
|---|---|
| arg= ' ABC.DEF(X=Y) ' ; word=scan(arg,3); put word; | X=Y |
| word=scan(arg,-3); put word; | ABC |