cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
Craige_Hales
Super User
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 otherwise value.

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.

Last Modified: Dec 21, 2023 1:19 PM