Previous Page | Next Page

SAS Component Language Dictionary

LOOKUPC



Searches for a string among a list of valid tokens
Category: Command

Syntax
Details
Example

Syntax

rc=LOOKUPC(string,token-1<, . . .,token-12>);

rc

contains the return code for the operation:

0

indicates that no match was found.

>0

is the position in the token list if a unique match was found.

<0

is the negative of the position in the token list if a duplicate token was found.

Type: Numeric

string

is the character value to search for.

Type: Character

token

is up to 12 character values, separated by commas.

Type: Character


Details

A token can be a name, a literal, digits, or special characters. This function is useful for looking up valid commands.

The function accepts abbreviations as valid commands. That is, the function reports a match if the search string matches the starting characters of a token.

LOOKUPC does not search the token list for embedded strings. For example, the search string LIST would not be found in the token NEWLIST.


Example

Get the command (SURVEY, NEWLIST, or ADDNAME) that the user issued from the command line, and execute code accordingly:

array cmds{*} $8 ('SURVEY','NEWLIST','ADDNAME');
INIT:
   control always;
return;
MAIN:
cmdword=WORD(1,'u');
cmdnum=lookupc(cmdword,cmds{1},cmds{2},cmds{3});
select;
when (cmdnum=1)
    ...SCL statements to process SURVEY command...
when (cmdnum=2)
    ...SCL statements to process NEWLIST command...
when (cmdnum=3)
   ...SCL statements to process ADDNAME command...
otherwise _msg_='Command conflict';
   end;

In this example, SUR, NEWL, and ADDN are considered valid commands.

Previous Page | Next Page | Top of Page