Chapter Contents

Previous

Next
INDEXW

INDEXW



Searches a character expression for a specified string as a word

Category: Character


Syntax
Arguments
Details
Comparisons
Examples
See Also

Syntax

INDEXW(source, excerpt)

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 blanks from excerpt.


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, INDEXW returns a value of 0. If there are multiple occurrences of the string, 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 blanks, the beginning of source, and the end of source. Punctuation marks are not word boundaries.


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. INDEX searches for any characters present in the excerpts.


Examples

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;
 


0


See Also

Functions:

INDEX
INDEXC


Chapter Contents

Previous

Next

Top of Page

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