INDEXW Function


Searches a character expression for a specified string as a word

Category: Character

Syntax

INDEXW ( source, excerpt <, delimiter >)

Arguments

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.

Details

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.

Comparisons

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.

Examples

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(' '));  
   

See Also

Functions:

  • 'INDEX Function' on page 589

  • 'INDEXC Function' on page 590




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net