$Select()

Returns a value associated with the first true truth-valued expression in a list of paired expression arguments.

The format for the $SELECT function is:

$S[ELECT](tvexpr:expr[,...])

$SELECT() is one of a limited set of functions that permit an indefinite number of arguments. $SELECT() provides a means of selecting from a list of alternatives.

Generally, the last $SELECT() argument has numeric literal one (1) for a truth-value to prevent run-time errors, and to provide a "default" value.

Examples of $SELECT()

Example:

GTM>for i=3:-1:0 write !,$select(i=1:"here",i=2:"come",i=3:"Watson")

Watson
come
here
%GTM-E-SELECTFALSE, No argument to $SELECT was true

GTM>

This loop uses $SELECT() to WRITE a series of strings. Because there is no true argument on the fourth iteration, when i=0, $SELECT() produces an error.

Example:

set name=$select(sex="M":"Mr. ",sex="F":"Ms. ",1:"")_name

This example uses $SELECT() to add a prefix to the name based on a sex code held in the variable sex. Notice that the default handles the case of a missing or incorrect code.

Example:

if $select(x=+x:x,x="":0,"JANAPRJULOCT"[x:1,1:0) do THING

This uses $SELECT() to perform complex logic as the truth-valued expression argument to an IF command.