The %KSCAN and %QKSCAN
functions search
argument and
return the
nth word. A word
is one or more characters separated by one or more delimiters.
%KSCAN does not mask
special characters or mnemonic operators in its results, even when
the argument was previously masked by a macro quoting function. %QKSCAN
masks the following special characters and mnemonic operators in its
results:
& % ' " ( ) + − * / < > = ¬ ^ ~ ; , # blank
AND OR NOT EQ NE LE LT GE GT IN
A
delimiter is any of several characters that
are used to separate words. You can specify the delimiters in the
charlist and
modifier arguments.
If you specify the Q
modifier, then delimiters inside of substrings that are enclosed in
quotation marks are ignored.
In the %KSCAN function,
word refers to a substring that has all of the
following characteristics:
-
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
-
A word can have a length
of zero if there are delimiters at the beginning or end of the string
or if the string contains two or more consecutive delimiters. However,
the %KSCAN function ignores words that have a length of zero unless
you specify the M modifier.
If you use the %KSCAN
function with only two arguments, then the default delimiters depend
on whether your computer uses ASCII or EBCDIC characters:
-
If your computer uses ASCII characters,
then the default delimiters are as follows:
blank ! $ % & (
) * + , - . / ; < ^¦
In ASCII environments
that do not contain the ^ character, the %KSCAN function uses the
~ character instead.
-
If your computer uses EBCDIC characters,
then the default delimiters are as follows:
blank ! $ % & (
) * + , - . / ; < ¬ | ¢¦
If you use the
modifier argument without specifying any characters
as delimiters, then the only delimiters that will be used are delimiters
that are defined by the
modifier argument. In this case, the lists of default delimiters for ASCII
and EBCDIC environments are not used. In other words, modifiers add
to the list of delimiters that are specified by the
charlist argument. Modifiers do not add to the
list of default modifiers.
If you specify the M
modifier, then the number of words in a string is defined as one plus
the number of delimiters in the string. However, if you specify the
Q modifier, delimiters that are inside quotation marks are ignored.
If you specify the M
modifier, then the %KSCAN function returns a word with a length of
zero if one of the following conditions is true:
-
The string begins with a delimiter
and you request the first word.
-
The string ends with a delimiter
and you request the last word.
-
The string contains two consecutive
delimiters and you request the word that is between the two delimiters.
If you do not specify
the M modifier, then the number of words in a string is defined as
the number of maximal substrings of consecutive nondelimiters. However,
if you specify the Q modifier, delimiters that are inside quotation
marks are ignored.
If you do not specify
the M modifier, then the %KSCAN function does the following:
-
ignores delimiters at the beginning
or end of the string
-
treats two or more consecutive
delimiters as if they were a single delimiter
If the string contains
no characters other than delimiters or if you specify a count that
is greater in absolute value than the number of words in the string,
then the %KSCAN function returns one of the following:
-
a single blank when you call the
%KSCAN function from a DATA step
-
a string with a length of zero
when you call the %KSCAN function from the macro processor
The %KSCAN function
allows character arguments to be null. Null arguments are treated
as character strings with a length of zero. Numeric arguments cannot
be null.