SCANQ Function


Returns the n th word from a character expression, ignoring delimiters that are enclosed in quotation marks

Category: Character

Syntax

SCANQ ( string , n <, delimiter (s) >)

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 SCANQ to select. The following rules apply:

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

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

    • If n is zero, or n is greater than the number of words in the character string, then SCANQ returns a string that contains no characters .

delimiter

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

  • Default: If you omit delimiter , 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

If the SCANQ function returns a value to a variable that has not yet been assigned a length, then by default the variable is assigned a length of 200.

In the context of the SCANQ function, '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.

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

If the value of the character string contains quotation marks, then 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.

Examples

In this example, SCANQ reads the input string and uses a blank space as the delimiter. SCANQ ignores the delimiter that is enclosed in quotation marks.

 options pageno=1 pagesize=60 linesize=80 nodate;  data nametest;     allnames='Eleanor "Billie Holiday" Fagan';     array new(*)  name1 name2 name3;     do i=1 to dim(new);        new(i)=scanq(allnames,i," ");     end;  run;  proc print data=nametest;  run; 
Output 4.48: Output from the SCANQ Function
start example
 The SAS System                              1  Obs               allnames              name1        name2         name3     i   1     Eleanor "Billie Holiday" Fagan  Eleanor  "Billie Holiday"   Fagan     4 
end example
 

See Also

Functions and CALL Routines:

  • 'SCAN Function' on page 815

  • 'CALL SCAN Routine' on page 389

  • 'CALL SCANQ Routine' on page 391




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