turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Blogs
- :
- Uncharted
- :
- If Secrets

Article Options

- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Email to a Friend
- Printer Friendly Page
- Report Inappropriate Content

May 23, 2017 12:58 PM
(603 views)

If Secrets

Secret one

The JSL If statement is actually a function, and it returns a value.

`print( if ( 1 < 2, "yes", "no" ) )`

**"yes"**

If you didn't know that, you might have written

`if ( 1 < 2, print("yes"), print( "no" ) )`

which also works.

Secret two

The JSL If function needs ** at least** two arguments. It can have more than three! If there is an odd number of arguments, the last one is the

```
n = 17;
classification = if(
n<3, "toddlers",
n<13, "children",
n<20, "teens",
"adults"
);
show( n, classification );
```

**n = 17;****classification = "teens";**

Secret three

The JSL If function handles missing values as neither true or false. The *otherwise* value is NOT the answer.

```
n = .;
classification = if(
n<3, "toddlers",
n<13, "children",
n<20, "teens",
"adults"
);
show( n, classification );
```

**n = .;****classification = .;**

This can seem quite surprising if you believe two missing values are equal to each other. JMP's comparison operators all return missing if either (or both) operands are missing values. JMP uses the isMissing function to test for missing:

```
n = .;
classification = if(
isMissing(n), "unknown",
n<3, "toddlers",
n<13, "children",
n<20, "teens",
"adults"
);
show( n, classification );
```

**n = .;****classification = "unknown";**

Secret four

There isn't really a secret, it's all on the web.

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.