Functions and CALL Routines

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
Arguments
Details
Comparisons
Examples
See Also

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:

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

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 $60.;
   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;

SAS Output from the CALL SCANQ Routine

                                 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       

See Also

Functions and CALL Routines:

SCAN Function

SCANQ Function

CALL SCAN Routine

space
Previous Page | Next Page | Top of Page