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
- :
- Discussions
- :
- Logical Test to check a range and return True or False

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Created:
Apr 26, 2020 1:18 AM
| Last Modified: Apr 26, 2020 7:47 AM
(465 views)

Hi,

l am trying to check if a value in a cell within a variable lies within a range of values, between 0.50 and 2.0, and if it does fall within that range to return true and if it doesnt return false. i am in the data table, and column info, and typing the following into the edit formula:

` If (0.50 < ( :Name( "P1-R1-D1-L1" ) > 2.0), "True", "False") `

// and

If (0.50 < ( :Name( "P1-R1-D1-L1" ))|(2.0 > ( :Name( "P1-R1-D1-L1" ), "True", "False"))

but neither is working for me, what am i doing wrong, any help would be greatly appreciated

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Here is a piece of JSL that creates a column under the specifications you provided

```
Names Default To Here( 1 );
dt = New Table( "Example",
add rows( 20 ),
New Column( "P1-R1-D1-L1", formula( Random Uniform( 0, 4 ) ) )
);
dt << New Column( "TorF",
character,
formula( If( 0.50 <= :Name( "P1-R1-D1-L1" ) <= 2.0, "True", "False" ) )
);
```

Jim

4 REPLIES 4

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Here is a piece of JSL that creates a column under the specifications you provided

```
Names Default To Here( 1 );
dt = New Table( "Example",
add rows( 20 ),
New Column( "P1-R1-D1-L1", formula( Random Uniform( 0, 4 ) ) )
);
dt << New Column( "TorF",
character,
formula( If( 0.50 <= :Name( "P1-R1-D1-L1" ) <= 2.0, "True", "False" ) )
);
```

Jim

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Logical Test to check a range and return True or False

once again thanks txnelson, thanks for all your help, greatly appreciated

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Logical Test to check a range and return True or False

@txnelson gave you a working example but I can explain what you've got wrong in your attempts.

`If (0.50 < ( :Name( "P1-R1-D1-L1" ) > 2.0), "True", "False")`

In this on you're trying a complex comparison that JMP doesn't support, namely a < b > c, i.e. a **less than** b **greater than** c.

Looking in the Formula Editor you can see the complex comparisons that JMP does offer, and that @txnelson used:

Notice the help text which gives a clue that JMP is a functional language and that these complex operators are really shorthand for the functions Less LessEqual() and LessEqual Less(). JMP doesn't have a function for the comparison you wanted to make.

For the second attempt:

`If (0.50 < ( :Name( "P1-R1-D1-L1" ))|(2.0 > ( :Name( "P1-R1-D1-L1" ), "True", "False"))`

You've got some more parentheses than needed and they are in the wrong places. Here's a corrected version:

```
If( 0.50 < :Name( "P1-R1-D1-L1" ) | 2.0 > :Name( "P1-R1-D1-L1" ),
"True",
"False"
)
```

However, let's consider what you're asking for in this logical comparison. You're asking JMP to check whether your column is **greater than** .5 __ or__ 2.0 is

So, you probably want the version that @txnelson provided, checking to see if your column is within the range .5 to 2.0 using the a < b <= c construct.

-Jeff

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Logical Test to check a range and return True or False

Thanks Jeff, great explanation

Article Labels

There are no labels assigned to this post.