cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
karmstro
Level III

IS NUMBER IS MISSING etc.

I have the following snippet of JSL that checks the My_Graphs list to determine whether the ith row is a number or not and do one of two things (col 6 consists of numbers and "."). The first part of the IF works - it sets the chart min at 1.2 the LCL and draws the plot. However, if the LCL is "." it does not set the LCL to 0. Immediately below is the the first 6 rows of col 6.

 

.
0.25
-2
-0.018
.
0.25

 

if(Is Number(num(My_Graphs [6][i])),

(Plot << dispatch(

{"Variability Chart for..."},

"2",

ScaleBox,

{Min(num(My_Graphs [6][i]) * 1.2 ),

Add Ref Line( num(My_Graphs [6][i]), Dotted, "Red", "LCL = " || My_Graphs [6][i] , 2 ),

Show Major Grid( 1 )})

),

(Plot << dispatch(

{"Variability Chart for..."},

"2", ScaleBox, {Min(0)})

)

);//end if

1 ACCEPTED SOLUTION

Accepted Solutions
kevin_lennon
Level III

Re: IS NUMBER IS MISSING etc.

Kev - let's have a chat about this in work...But I think I see your problem.

JMP treats a missing number as a number. So when you execute the code below it returns "It's a number" for every element of num_list.

 

num_list = {.,0.25,-2,-0.018,.,0.25};

for(i=1,i<=nitems(num_list),i++,if(IsNumber(num_list[i]),Print("It's a number"), Print ("It's not a number")));

 

What I suggest you do instead is change your if condition to handle the missing one first, followed by is number and then some catch expression.

 

num_list = {.,0.25,-2,-0.018,.,0.25};

for(i=1,i<=nitems(num_list),i++,if(IsMissing(num_list[i]),Print("It's Missing"), IsNumber(num_list[i]), Print ("It's a number"),Print("I don't know what to do now")));

 

 

 

 

View solution in original post

10 REPLIES 10
Craige_Hales
Super User

Re: IS NUMBER IS MISSING etc.


x=.;
show( x, isNumber(1), isNumber(0), isNumber(.), isMissing(0), isMissing(.), if( x==x, "yes", "no") )

x = .;
Is Number(1) = 1;
Is Number(0) = 1;
Is Number(.) = 1;
Is Missing(0) = 0;
Is Missing(.) = 1;
If(x == x, "yes", "no") = .;

Missing values are numbers and require the isMissing function to test for them.  A comparison against a missing value returns missing, not 0 or 1, even if both values are missing.

Craige
karmstro
Level III

Re: IS NUMBER IS MISSING etc.

This should work then but it doesn't?

 

if(!Is Missing(My_Graphs [6][i]),

(Plot << dispatch(

{"Variability Chart..."},

"2",

ScaleBox,

{Min(num(My_Graphs [6][i]) * 1.2 ),

Add Ref Line( num(My_Graphs [6][i]), Dotted, "Red", "LCL = " || My_Graphs [6][i] , 2 ),

Show Major Grid( 1 )})

),

(Plot << dispatch(

{"Variability Chart..."},

"2", ScaleBox, {Min(0)})

)

);//end if

Jeff_Perkinson
Community Manager Community Manager

Re: IS NUMBER IS MISSING etc.

When you say it doesn't work, what exactly do you mean? Are you getting an error? Is the graph updated incorrectly? Not at all?

 

Can you add a

 

Show (My_Graphs [6][i]);

just before your conditional to see what the value is?

 

 

-Jeff
karmstro
Level III

Re: IS NUMBER IS MISSING etc.

It seems that it doesn't evaluate the false condition for !Is Missing but there's no error.

It updates the min and adds the chart line when there is a value but doesn't set min to 0 for false condition of if. 

Jeff_Perkinson
Community Manager Community Manager

Re: IS NUMBER IS MISSING etc.

We know that the Is Missing() function works. For example:

 

For( i = 1, i <= N Items( x ), i++,
	Print( "starting iteration " || Char( i ) );
	If( !Is Missing( x[i] ),
		Show( x[i] ),
		Print( "x is missing" );
		Show( x[i] );
	);
);
/*: "starting iteration 1" x[i] = 1; "starting iteration 2" "x is missing" x[i] = .;

So it must be something with the data/values that you're passing to it. That's why the Show() that I suggested above will help.

 

Maybe you should put a debugging "Show()" in the else clause of the If() as well to show whether it got in there or not.

 

 

 

-Jeff
karmstro
Level III

Re: IS NUMBER IS MISSING etc.

I'm passing it values from a list created with Summarize which are quoted values?

karmstro
Level III

Re: IS NUMBER IS MISSING etc.

When I run the following code I get:

 

For( i = 1, i <= number, i++, 

show(My_Graphs[6][i]);

);

 

My_Graphs[6][i] = ".";

My_Graphs[6][i] = "0.25";

My_Graphs[6][i] = "-2";

My_Graphs[6][i] = "-0.018";

My_Graphs[6][i] = ".";

 

When I run the followng code I get:

 

For( i = 1, i <= number, i++,

show(Is Missing(My_Graphs[6][i])); 

);

 

Is Missing(My_Graphs[6][i]) = 0;

Is Missing(My_Graphs[6][i]) = 0;

Is Missing(My_Graphs[6][i]) = 0;

Is Missing(My_Graphs[6][i]) = 0;

Is Missing(My_Graphs[6][i]) = 0;

 

When I run the following code I get:

 

For( i = 1, i <= number, i++,

 

show(Is Missing(num(My_Graphs[6][i])));

 

);

 

Is Missing(Num(My_Graphs[6][i])) = 1;

Is Missing(Num(My_Graphs[6][i])) = 0;

Is Missing(Num(My_Graphs[6][i])) = 0;

Is Missing(Num(My_Graphs[6][i])) = 0;

Is Missing(Num(My_Graphs[6][i])) = 1;

 

It looks like  have to covert the list strings to num for the Is Missing function.

Jeff_Perkinson
Community Manager Community Manager

Re: IS NUMBER IS MISSING etc.


@karmstro wrote:

When I run the following code I get:

 

For( i = 1, i <= number, i++, 

show(My_Graphs[6][i]);

);

 

My_Graphs[6][i] = ".";

My_Graphs[6][i] = "0.25";

My_Graphs[6][i] = "-2";

My_Graphs[6][i] = "-0.018";

My_Graphs[6][i] = ".";

 

The quote marks indicate that your values are character strings. As such you'll need to convert them to numbers using the Num() function in order to use the Is Missing() function.

 

So it should be:

 

if(Is Missing(num(My_Graphs [6][i])),
(Plot << dispatch(
{"Variability Chart for..."},
"2",
ScaleBox,
{Min(num(My_Graphs [6][i]) * 1.2 ),
Add Ref Line( num(My_Graphs [6][i]), Dotted, "Red", "LCL = " || My_Graphs [6][i] , 2 ),
Show Major Grid( 1 )})
),
(Plot << dispatch(
{"Variability Chart for..."},
"2", ScaleBox, {Min(0)})
)
);//end if

Which is really close to what you had originally.

 

Alternatively, you could compare against the text string "." like this:

 

if(My_Graphs [6][i] == ".",
(Plot << dispatch(
{"Variability Chart for..."},
"2",
ScaleBox,
{Min(num(My_Graphs [6][i]) * 1.2 ),
Add Ref Line( num(My_Graphs [6][i]), Dotted, "Red", "LCL = " || My_Graphs [6][i] , 2 ),
Show Major Grid( 1 )})
),
(Plot << dispatch(
{"Variability Chart for..."},
"2", ScaleBox, {Min(0)})
)
);//end if

 

 

 

-Jeff
kevin_lennon
Level III

Re: IS NUMBER IS MISSING etc.

Kev - let's have a chat about this in work...But I think I see your problem.

JMP treats a missing number as a number. So when you execute the code below it returns "It's a number" for every element of num_list.

 

num_list = {.,0.25,-2,-0.018,.,0.25};

for(i=1,i<=nitems(num_list),i++,if(IsNumber(num_list[i]),Print("It's a number"), Print ("It's not a number")));

 

What I suggest you do instead is change your if condition to handle the missing one first, followed by is number and then some catch expression.

 

num_list = {.,0.25,-2,-0.018,.,0.25};

for(i=1,i<=nitems(num_list),i++,if(IsMissing(num_list[i]),Print("It's Missing"), IsNumber(num_list[i]), Print ("It's a number"),Print("I don't know what to do now")));