Returns the position and length of a given word from a character expression
Category: Character
CALL SCAN ( string , n , position , length <, delimiters >);
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:
If n is positive, CALL SCAN counts words from left to right.
If n is negative, CALL SCAN counts words from right to left.
If n is zero, or n is greater than the number of words in the character string, CALL SCAN 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 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.
In the context of the CALL SCAN 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.
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)
The CALL SCANQ routine ignores delimiters that are enclosed in quotation marks. CALL SCAN does not.
The following example shows how you can use the CALL SCAN routine.
options pageno=1 nodate ls=80 ps=64; data artists; input string .; 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;
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
Functions and CALL Routines:
'SCAN Function' on page 815
'SCANQ Function' on page 816
'CALL SCANQ Routine' on page 391