cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
UserID16644
Level V

How to get variable value inside IF Condition

Hi all,

I am stucked in this IF Condition, where I need to get the variable value(color) based on another column value (:Fruit). It always return an empty variable color. Please help

 

 

Here's my sample code: 

If( :Fruit == "Apple",
color= "Red"; Target = {50};,
:Fruit == "Grapes",
color= "Violet"; Target = {50};,
:Fruit == "Cherry",
color= "Red"; Target = {54};
);
1 ACCEPTED SOLUTION

Accepted Solutions
Thierry_S
Super User

Re: How to get variable value inside IF Condition

Hi,

 

It is unclear what you are trying to do given the limited context. Is this part of a JSL script or a column Formula? If it is the latter, you need to specify what the expression returns as shown below:

If(
	:Fruit == "Apple",
		color = "Red";
		Target = {50};,
	:Fruit == "Grapes",
		color = "Violet";
		Target = {50};,
	:Fruit == "Cherry",
		color = "Red";
		Target = {54};
);
color;

Also,  are you sure that the column's content :Fruit matches precisely the values in your expression (i.e., no leading or trailing spaces)?

An example of the usage context for this expression would help figure out what may be going on.

Best,

TS 

Thierry R. Sornasse

View solution in original post

2 REPLIES 2
Thierry_S
Super User

Re: How to get variable value inside IF Condition

Hi,

 

It is unclear what you are trying to do given the limited context. Is this part of a JSL script or a column Formula? If it is the latter, you need to specify what the expression returns as shown below:

If(
	:Fruit == "Apple",
		color = "Red";
		Target = {50};,
	:Fruit == "Grapes",
		color = "Violet";
		Target = {50};,
	:Fruit == "Cherry",
		color = "Red";
		Target = {54};
);
color;

Also,  are you sure that the column's content :Fruit matches precisely the values in your expression (i.e., no leading or trailing spaces)?

An example of the usage context for this expression would help figure out what may be going on.

Best,

TS 

Thierry R. Sornasse

Re: How to get variable value inside IF Condition

You might consider the more specialized conditional function Match(). It is a nice alternative that is perhaps clearer as far as the intent and the result

 

Match( :Fruit,
	"Apple",
		color = "Red";
		Target = {50};,
	"Grapes",
		color = "Violet";
		Target = {50};,
	"Cherry",
		color = "Red";
		Target = {54};
);

Recommended Articles