Functions and CALL Routines

CALL SCAN Routine



Returns the position and length of a given word from a character expression
Category: Character

Syntax
Arguments
Details
Comparisons
Examples
See Also

Syntax

CALL SCAN(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 SCAN 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 SCAN to use to separate words in the character string.

Default: If you omit delimiters in an ASCII environment, SAS uses the following characters:

blank . < ( + & ! $ * ) ; ^ - / , % |

In ASCII environments without the ^ character, SCAN uses the ~ character instead.

If you omit delimiters in an EBCDIC environment, SAS uses the following characters:

blank . < ( + | & ! $ * ) ; ¬ - / , % | ¢

Tip: If you represent delimiters as a constant, enclose delimiters in quotation marks.

Details

In the context of the CALL SCAN routine, "word" refers to a substring that

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

To retrieve the designated word as a character string after the call to CALL SCAN, 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 SCAN routine.

options pageno=1 nodate ls=80 ps=64;

data artists;
   input string $60.;
   drop string;
   do i=1 to 99;
      call scan(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=artists;
run;

SAS Output from the CALL SCAN Routine

                                 The SAS System                                1

                  Obs    i    position    length    Name

                   1     1        1          7      Picasso  
                   2     2        9          8      Toulouse 
                   3     3       18          7      Lautrec  
                   4     4       26          6      Turner   
                   5     5       33          4      "Van     
                   6     6       38          5      Gogh"    
                   7     7       44          9      Velazquez

See Also

Functions and CALL Routines:

SCAN Function

SCANQ Function

CALL SCANQ Routine

space
Previous Page | Next Page | Top of Page