FIND Function


Searches for a specific substring of characters within a character string that you specify

Category: Character

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 .

  • Tip: If the 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 that evaluates to one or more constants.

startpos

  • is an integer 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.

When startpos is

then FIND

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

  • The FIND function searches for substrings of characters in a character string, whereas the FINDC function searches for individual characters in a character string.

  • The FIND function and the INDEX function both search for substrings of characters in a character string; however, the INDEX function does not have the modifiers nor the startpos arguments.

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' on page 468

  • 'FINDC Function' on page 535

  • 'INDEX Function' on page 589

  • 'RXMATCH Function' on page 799




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