Publication date: 08/13/2020

Comparing data that contains missing values can return misleading results unless you specify a condition that is always true or use functions such as Is Missing() or Zero Or Missing(). Comparisons of data with mismatched types (numeric versus character) or data in matrices can also be confusing.

Table 5.5 shows examples of such comparisons and matrices and explanations of the results. For a review of operators used in comparisons, see Operators. For an overview of comparing data, see Comparison Functions in the JSL Syntax Reference.

Note: Matrices must include the same number of columns or rows.

Test |
Result |
Explanation |
---|---|---|

m=.; m==1 |
. |
An equality test with a missing value returns missing. |

m=.; m!=1 |
. |
An inequality test with a missing value returns missing. |

m=.; m<1; m>1; and so on |
. |
A comparison with a missing value returns missing (unless it could not possibly be true, see next). |

m=.; 1<m<0 |
0 |
A comparison involving a missing value that could not possibly be true returns false; false takes precedence over missing for comparisons with more than two arguments (as with logical operators). |

{a, b}==List(a, b) |
1 |
An equality test of list arguments returns a single result. |

{a, b}<{a, c} |
. |
A comparison test of list arguments is not allowed. |

1=="abc" |
0 |
An equality test with mixed data types returns false. |

1<="abc" |
. |
A comparison with mixed data types returns missing. |

[1 2 3]==[2 2 5] |
[0 1 0] |
An equality test of matrices returns a matrix of elementwise results. When a matrix is compared to a matrix, comparison is done element-by-element and returns a matrix of 1s and 0s. |

[1 2 3]==2 |
[0 1 0] |
An equality test of a matrix and a matrix filled with 2s. If a matrix is compared to a number, the number is treated as a matrix filled with that number. |

[1 2 3] < [2 2 5] |
[1 0 1] |
A comparison of matrices returns a matrix of elementwise results. |

[1 2 3] < 2 |
[1 0 0] |
A comparison of a matrix and a matrix filled with 2s. |

Is Missing(m) |
1 |
Returns 1 for a missing value and returns 0 otherwise. For missing character values, you can also use empty quotes for the comparison, as in m == "". |

Zero Or Missing(m) |
1 |
Returns 1 when the value is 0 or missing. The argument must be numeric or a matrix and not a string. |

All([2 2]==[1 2]) |
0 |
Summarizes elementwise comparisons; returns 1 only if all comparisons are true and returns 0 otherwise. |

Any([2 2]==[1 2]) |
1 |
Summarizes elementwise comparisons; returns 1 if any comparison is true and returns 0 otherwise. |

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).

.