Previous Page | Next Page

Functions and CALL Routines

CHOOSEC Function



Returns a character value that represents the results of choosing from a list of arguments.
Category: Character
Restriction: I18N Level 2

Syntax
Arguments
Details
Length of Returned Variable
The Basics
Comparisons
Examples
See Also

Syntax

CHOOSEC (index-expression, selection-1 <,...selection-n>)

Arguments

index-expression

specifies a numeric constant, variable, or expression.

selection

specifies a character constant, variable, or expression. The value of this argument is returned by the CHOOSEC function.


Details


Length of Returned Variable

In a DATA step, if the CHOOSEC function returns a value to a variable that has not previously been assigned a length, then that variable is given a length of 200 bytes.


The Basics

The CHOOSEC function uses the value of index-expression to select from the arguments that follow. For example, if index-expression is three, CHOOSEC returns the value of selection-3. If the first argument is negative, the function counts backwards from the list of arguments, and returns that value.


Comparisons

The CHOOSEC function is similar to the CHOOSEN function except that CHOOSEC returns a character value while CHOOSEN returns a numeric value.


Examples

The following example shows how CHOOSEC chooses from a series of values:

data _null_;
   Fruit=choosec(1,'apple','orange','pear','fig');
   Color=choosec(3,'red','blue','green','yellow');
   Planet=choosec(2,'Mars','Mercury','Uranus');
   Sport=choosec(-3,'soccer','baseball','gymnastics','skiing');
   put Fruit= Color= Planet= Sport=;
run;

SAS writes the following line to the log:

Fruit=apple Color=green Planet=Mercury Sport=baseball


See Also

Functions:

CHOOSEN Function

Previous Page | Next Page | Top of Page