Lookup


Contents

Description

This function searches for a string pattern str within a vector vs and, if found, returns a value from vector vref with the same index. Vector vref may be contain numeric or string values. By default, the function searches vs for the full string (option = 2). If no match if found and vref is numeric, the function returns a missing value ("--"); when vref contains strings, an empty string is returned.

The function will return the closest match, using option =0 or =1, but Lookup() does not support wildcard characters.

Syntax

If vref contains numeric values,

 double Lookup(string str$, vector<string> vs, vector vref[, int option, int Case])

If vref contains string values,

 string Lookup(string str$, vector<string> vs, vector<string> vref[, int option, int Case])$

Parameters

str

is the string pattern to find in vector vs

vs

is the vector in which string pattern str is looked up.

vref

is the reference vector whose nth value will be returned. n is the index of string str within vector vs.

option

[optional] integer that specifies how the string is matched:

Case

[optional] integer that specifies whether the search is case sensitive.

Return

If str is found in vs, returns a value in vector vref of the same row index.

If option = 2, and str is not found, returns an empty string or missing value.

If option = 0 and str is not found, returns the value corresponding to the nearest smaller value of str. If no smaller value of str exists, returns missing value (numeric) or empty string (string).

If option = 1 and str is not found, returns the value corresponding to the nearest larger value of str. If no larger value of str exists, returns missing value (numeric) or empty string (string).

Example

range aa=1!col(A);
range bb=1!col(B);
string str1$ = Lookup("FSA", aa, bb)$;
str1$=;