CALL SCANQ Routine


Returns the position and length of a given word from a character expression, and ignores delimiters that are enclosed in quotation marks

Category: Character

Syntax

CALL SCANQ ( string , n , position , length <, delimiters >);

Arguments

string

  • specifies a character constant, variable, or expression.

n

  • is a numeric constant, variable, or expression that specifies the number of the word in the character string that you want the CALL SCANQ routine to select. The following rules apply:

    • If n is positive, CALL SCANQ counts words from left to right.

    • If n is negative, CALL SCANQ counts words from right to left.

    • If n is zero, or n is greater than the number of words in the character string, CALL SCANQ returns a position and length of zero.

position

  • specifies a numeric variable in which the position of the word is returned.

length

  • specifies a numeric variable in which the length of the word is returned.

delimiters

  • is a character constant, variable, or expression that specifies the characters that you want CALL SCANQ to use to separate words in the character string.

  • Default: If you omit delimiters CALL SCANQ uses white space characters (blank, horizontal and vertical tab, carriage return, line feed, and form feed) as delimiters.

  • Restriction: You cannot use single or double quotation marks as delimiters.

Details

In the context of the CALL SCANQ routine, 'word' refers to a substring that

  • is bounded on the left by a delimiter or the beginning of the string

  • is bounded on the right by a delimiter or the end of the string

  • contains no delimiters except those that are enclosed in quotation marks.

If the value of the character string contains quotation marks, CALL SCANQ ignores delimiters inside the strings in quotation marks. If the value of the character string contains unmatched quotation marks, then scanning from left to right will produce different words than scanning from right to left.

Delimiters that are located before the first word or after the last word in the character string do not affect the CALL SCANQ routine. If two or more contiguous delimiters exist, CALL SCANQ treats them as one.

To retrieve the designated word as a character string after the call to CALL SCANQ, use the following function:

 substrn(string, position, length) 

Comparisons

The CALL SCANQ routine ignores delimiters that are enclosed in quotation marks. CALL SCAN does not.

Examples

The following example shows how you can use the CALL SCANQ routine.

 options pageno=1 nodate ls=80 ps=64;  data artists2;     input string .;     drop string;     do i=1 to 99;        call scanq(string, i, position, length);        if not position then leave;        Name=substrn(string, position, length);        output;     end;     datalines;  Picasso Toulouse-Lautrec Turner "Van Gogh" Velazquez  ;  proc print data=artists2;  run; 
Output 4.16: SAS Output from the CALL SCANQ Routine
start example
 The SAS System                                     1  Obs     i     position     length     Name    1     1         1           7       Picasso    2     2         9          16       Toulouse-Lautrec    3     3        26           6       Turner    4     4        33          10       "Van Gogh"    5     5        44           9       Velazquez 
end example
 

See Also

Functions and CALL Routines:

  • 'SCAN Function' on page 815

  • 'SCANQ Function' on page 816

  • 'CALL SCAN Routine' on page 389




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