Publication date: 07/08/2024

Choose Function

The Choose() function shortens scripts even more than Match(), provided the arguments are tested against integers. The syntax is:

Choose( expr, result1, result2, result3, ..., resultElse );

Suppose you have a data table with a group column of numeric values from 1 through 7. If the first cell contains the number 1, the following script returns x = "Low".

x = ( Choose( group[1], "Low", "Medium", "High", "Unknown" ); );
Show( x );

The script works like this:

x =

Creates the x variable.

Choose(

Begins the Choose() loop.

group[1],

Evaluates the value of group in the first row.

"Low",

If the value of group is 1, return "Low".

"Medium",

If the value of group is 2, return "Medium".

"High",

If the value of group is 3, return "High".

"Unknown"

Otherwise, return "Unknown".

)

Ends the loop.

);

Closes the x variable.

Show( x );

Returns the value of x.

If the expression evaluates to an out-of-range integer (such as 7 when only 4 replacement values are listed), the last result is returned. In the preceding example, "Unknown" is returned.

Notice that If() and Match() require more code to achieve the same results as the Choose function:

If(
	group[1] == 1, "Low",
	group[1] == 2, "Medium",
	group[1] == 3, "High",
	"Unknown"
);
Match( group, 1, "Low", 2, "Medium", 3, "High", "Unknown" );

Note: If the data types in the expression do not match, JMP automatically changes the column’s data type.

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).