cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar

Using the Match Function and the Choose Function

Started ‎11-08-2022 by
Modified ‎11-08-2022 by
View Fullscreen Exit Fullscreen

It's common to have conditions that are limited to specific values, and these values could be numeric or character data. You can use the Match function in this situation. The Match function is a specialized conditional function that takes three or more arguments. The first argument is evaluated and used as the value to be matched. The second argument is evaluated and interpreted as a Boolean value. If the value is true -- in other words, the second argument matches the result of the first argument -- then the third argument is evaluated, and that result is returned as the result of the Match function. Otherwise, the third argument isn't evaluated, and the Match function returns a missing value. Like the If function, you can have as many pairs of value and result arguments as needed, and like the If function, once a true result is returned, the corresponding odd-numbered argument is evaluated, and none of the remaining arguments are. And of course, it's also possible to include an else result in the Match function. Using this optional final argument means that the function will never return a missing value. Instead, if none of the previous even-numbered arguments return a true result, the function returns the else result. An even more specialized situation is when the conditions are represented by an index (that is, an integer value greater than zero). In this case, you can use the Choose function, which takes at least two arguments. The first argument is an expression that's evaluated and used to determine the index of the correct result argument, and then the corresponding result is returned as the result of the Choose function. In the example shown, we use the Day of Week function, which returns an integer value for each day of the week. So if the expression evaluates to for example, then the third result (in this case, Tuesday), is returned. Unlike the If and Match functions, the Choose function never returns a missing value. Instead, if the result of the expression is an index higher than the number of result arguments, then the last argument is evaluated and returned as the result of the Choose function.