Choose Language Hide Translation Bar
Highlighted
Mickyboy
Level IV

Logical Test to check a range and return True or False

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
txnelson
Super User

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

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

View solution in original post

4 REPLIES 4
Highlighted
txnelson
Super User

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

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

View solution in original post

Highlighted
Mickyboy
Level IV

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

once again thanks txnelson, thanks for all your help, greatly appreciated
Highlighted
Jeff_Perkinson
Community Manager Community Manager

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:

 

2020-04-26_11-01-47.904.png

 

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 greater than your column. This will be true for all values of your column. If your column is less than .5, then 2.0 will be greater than your column. If your column is greater than 2.0 then .5 will be less than your column.

 

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
Mickyboy
Level IV

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.