Searches a character expression for a specified string as a word
Category: Character
INDEXW ( source, excerpt <, delimiter >)
source
specifies the character expression to search.
excerpt
specifies the string of characters to search for in the character expression. SAS removes the leading and trailing delimiters from excerpt .
delimiter
specifies a character expression that you want INDEXW to use as a word separator in the character string. The default delimiter is the blank character.
The INDEXW function searches source , from left to right, for the first occurrence of excerpt and returns the position in source of the substring's first character. If the substring is not found in source , then INDEXW returns a value of 0. If there are multiple occurrences of the string, then INDEXW returns only the position of the first occurrence.
The substring pattern must begin and end on a word boundary. For INDEXW, word boundaries are delimiters, the beginning of source , and the end of source .
INDEXW has the following behavior when the second argument contains blank spaces or has a length of 0:
If both source and excerpt contain only blank spaces or have a length of 0, then INDEXW returns a value of 1.
If excerpt contains only blank spaces or has a length of 0, and source contains character or numeric data, then INDEXW returns a value of 0.
The INDEXW function searches for strings that are words, whereas the INDEX function searches for patterns as separate words or as parts of other words. INDEXC searches for any characters that are present in the excerpts.
The following SAS statements give these results.
SAS Statements | Results |
---|---|
s='asdf adog dog'; p='dog '; x=indexw(s,p); put x; | 11 |
s='abcdef x=y'; p='def'; x=indexw(s,p); put x; | |
x="abc,def@ xyz"; abc=indexw(x, " abc ", "@"); put abc; | |
x="abc,def@ xyz"; comma=indexw(x, ",", "@"); put comma; | |
x="abc,def% xyz"; def=indexw(x, "def", "%"); put def; | 5 |
x="abc,def@ xyz"; at=indexw(x, "@", "@"); put at; | |
x="abc,def@ xyz"; xyz=indexw(x, " xyz", "@"); put xyz; | 9 |
c=indexw(trimn(' '), ' '); | 1 |
g=indexw(' x y ', trimn(' ')); | |
Functions:
'INDEX Function' on page 589
'INDEXC Function' on page 590