Previous Page | Next Page

Functions and CALL Routines

FIND Function



Searches for a specific substring of characters within a character string.
Category: Character
Restriction: I18N Level 1
Tip: Use the KINDEX function in SAS National Language Support (NLS): Reference Guide instead to write encoding independent code.

Syntax
Arguments
Details
Comparisons
Examples
See Also

Syntax

FIND(string,substring<,modifiers><,startpos>)
FIND(string,substring<,startpos><,modifiers>)


Arguments

string

specifies a character constant, variable, or expression that will be searched for substrings.

Tip: Enclose a literal string of characters in quotation marks.
substring

is a character constant, variable, or expression that specifies the substring of characters to search for in string.

Tip: Enclose a literal string of characters in quotation marks.
modifiers

is a character constant, variable, or expression that specifies one or more modifiers. The following modifiers can be in uppercase or lowercase:

i

ignores character case during the search. If this modifier is not specified, FIND only searches for character substrings with the same case as the characters in substring.

t

trims trailing blanks from string and substring.

Note:   If you want to remove trailing blanks from only one character argument instead of both (or all) character arguments, use the TRIM function instead of the FIND function with the T modifier.  [cautionend]

Tip: If modifier is a constant, enclose it in quotation marks. Specify multiple constants in a single set of quotation marks. Modifier can also be expressed as a variable or an expression.
startpos

is a numeric constant, variable, or expression with an integer value that specifies the position at which the search should start and the direction of the search.


Details

The FIND function searches string for the first occurrence of the specified substring, and returns the position of that substring. If the substring is not found in string, FIND returns a value of 0.

If startpos is not specified, FIND starts the search at the beginning of the string and searches the string from left to right. If startpos is specified, the absolute value of startpos determines the position at which to start the search. The sign of startpos determines the direction of the search.

Value of startpos
Action
greater than 0 starts the search at position startpos and the direction of the search is to the right. If startpos is greater than the length of string, FIND returns a value of 0.
less than 0 starts the search at position -startpos and the direction of the search is to the left. If -startpos is greater than the length of string, the search starts at the end of string.
equal to 0 returns a value of 0.


Comparisons


Examples

SAS Statements Results
whereisshe=find('She sells seashells? Yes, she does.','she ');
put whereisshe;
27
variable1='She sells seashells? Yes, she does.';
variable2='she ';
variable3='i';
whereisshe_i=find(variable1,variable2,variable3);
put whereisshe_i;



1
expression1='She sells seashells? '||'Yes, she does.';
expression2=kscan('he or she',3)||'  ';
expression3=trim('t   ');
whereisshe_t=find(expression1,expression2,expression3);
put whereisshe_t;



14
xyz='She sells seashells? Yes, she does.';
startposvar=22;
whereisshe_22=find(xyz,'she',startposvar);
put whereisshe_22;


27
xyz='She sells seashells? Yes, she does.';
startposexp=1-23;
whereisShe_ineg22=find(xyz,'She','i',startposexp);
put whereisShe_ineg22;


14


See Also

Functions:

COUNT Function

FINDC Function

INDEX Function

Previous Page | Next Page | Top of Page