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 If Action

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

The most general way to test conditions is to use the If function. Let's take a look at it in the context of iterating down the rows of a data table to populate a column called "grade" using the For Each Row function. In fact, we'll look at each of the conditional functions in the context of the For Each Row function. Now, the number of arguments for the If function varies, but at least two arguments are required. The first argument is always a condition: it's evaluated and interpreted as a Boolean result. If the result of that condition is true, then the second argument is evaluated and returned as the result of the If function. But if the result of the condition is false, then the second argument is not evaluated and the If function returns a missing value. Of course, it's also possible to call the If function with three arguments. In that case, the first argument is evaluated and interpreted as a Boolean result. If the condition is true, the second argument is evaluated and returned as the result of the If function. And, if the condition is true, the third argument will not be evaluated. However, if the result of the first argument is false, the second argument is not evaluated, and the third argument is evaluated and returned as the result of the If function. You can also call the If function with four arguments. JMP evaluates the first argument and interprets it as a Boolean result. And if the result is true, then the second argument is evaluated and returned as the result of the If function, and the third and fourth arguments are not evaluated. If the result is false, then the second argument is not evaluated, and the third argument is evaluated and interpreted as a Boolean result. If the result of the third argument is true, then the fourth argument is evaluated and returned as the result of the If function. But, if the result of the third argument is false, then the fourth argument is not evaluated and the If function returns a missing value. And guess what? It's also possible to call the If function with five arguments. The first argument is evaluated and interpreted as a Boolean result. If the result is true, then the second argument is evaluated and returned as the result of the If function. The third, fourth, and fifth arguments are not evaluated. If the result is false, then the third argument is evaluated and interpreted as a Boolean result. If the result of the third argument is true, then the fourth argument is evaluated and returned as a result of the If function. The second and fifth arguments are not evaluated. Finally, if the result is false, then the fourth argument is not evaluated and the fifth argument is evaluated and returned as a result. In fact, it's possible to assign any number of arguments to the If function. If there are an even number of arguments, the odd numbered arguments are conditions, and the even numbered arguments are the results returned if a condition is true. If none of the conditions evaluate as true, then the If function returns a missing value. If there are an odd number of arguments, the last argument is an Else result, and that's what's returned if none of the conditions evaluate as true. It's important to note that as soon as a condition evaluates as true, and the corresponding result argument is evaluated, no other arguments will be evaluated. In other words, your If statement could have more than one condition that's true, but as soon as the first true condition is encountered, none of the other conditions will be evaluated.