I know (now..) that if you have a possibility of having missing value and you would like to have it evaluated as 0 you should use IfMZ in JMP. What I'm wondering what is happening in the example below, if you have if-statement with "two elses" (won't return syntax error). In the example below it is expression if_expr_three
(and same for ifmz_expr_three
Names Default To Here(1);
if_expr_two = Expr(
res = If(val,
Print(Eval Insert("if_expr_two\!t^val^\!ttrue"));
1;
,
Print(Eval Insert("if_expr_two\!t^val^\!tfalse"));
0
);
show(res);
);
// what does this evaluate to and why does val = . return second statement
if_expr_three = Expr(
res = If(val,
Print(Eval Insert("if_expr_three\!t^val^\!ttrue"));
1;
,
Print(Eval Insert("if_expr_three\!t^val^\!tfalse?"));
0;
,
Print(Eval Insert("if_expr_three\!t^val^\!tsomething?"));
-1;
);
show(res);
);
ifmz_expr_two = Expr(
res = IfMZ(val,
Print(Eval Insert("ifmz_expr_two\!t^val^\!ttrue"));
1;
,
Print(Eval Insert("ifmz_expr_two\!t^val^\!tfalse"));
0;
);
show(res);
);
ifmz_expr_three = Expr(
res = IfMZ(val,
Print(Eval Insert("ifmz_expr_three\!t^val^\!ttrue"));
1;
,
Print(Eval Insert("ifmz_expr_three\!t^val^\!tfalse?"));
0;
,
Print(Eval Insert("ifmz_expr_three\!t^val^\!tsomething?"));
-1;
);
show(res);
);
val = 1;
if_expr_two; // OK, prints true and returns 1
if_expr_three; // OK?, prints true and returns 1
ifmz_expr_two; // OK, prints true and returns 1
ifmz_expr_three; // OK?, prints true and returns 1
Write("\!N");
val = 0;
if_expr_two; // OK, prints false and returns 0
if_expr_three; // ? prints false?, but returns missing
ifmz_expr_two; // OK, prints false and returns 0
ifmz_expr_three; // ? prints false?, but returns missing
Write("\!N");
val = .;
if_expr_two; // OK, no print but returns missing value
if_expr_three; // ? prints false? and returns missing
ifmz_expr_two; // OK, prints false and returns 0
ifmz_expr_three; // ? prints false? and returns missing
Write();
I will most likely send question about this to JMP support but I want to also ask for opinions in JMP community.
This is a bit similar case as Associative arrays and removal of keys with value same as default value in that sense that I'm not sure why this is happening (I did send message about that to jmp support, still waiting for final answer).
-Jarmo