Most likely someone from JMP has to provide the correct answer . @EvanMcCorkle ?
I'm not sure about the exact reason, but one reason is that the col won't get evaluated inside the formula (change Eval() to Expr() to force column name inside As Column()) (Or I think you can run << run formulas after formula creation and then remove formula immediately to make sure it won't get re-evaluated with incorrect column).
If col is the variable you store for each container values, it won't exist outside the loop with those values (setting xcol to col somewhat bypasses this)
Names Default To Here(1);
a = {"a", "b", "c"};
b = "z";
show(b);
For Each({b}, a,
show(b);
);
show(b);
/*
b = "z";
b = "a";
b = "b";
b = "c";
b = "z";
*/
I prefer using this method (Expr(NameExpr(AsColumn())) as this leaves the formula "cleaner" (:name instead of AsColumn("name").
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/semiconductor capability.jmp");
colNames = (dt << get column names(continuous, string))[1::10];
For Each({col}, colNames,
theTarget = (Column(Eval(col)) << get property("Spec Limits"))["Target"];
Eval(
Eval Expr(
New Column(col || " Minus Target",
Numeric,
"Continuous",
Format("Best", 10),
Formula(Expr(NameExpr(As Column(col))) - Expr(theTarget))
)
)
);
);
This is most likely not the same issues as ... Each loops have with function local scope (this is extremely annoying ... Each loops do not behave properly with function's local scope. I have reported this to JMP support)
Names Default To Here(1);
b = 2;
my_f = function({a}, {Default Local},
c = Transform Each({item}, a,
a * b
);
return(c);
);
my_f2 = function({a}, {Default Local},
b = b; // "Fix"
c = Transform Each({item}, a,
a * b
);
return(c);
);
Try(
show(my_f({1,2,3}));
,
show(exception_msg);
);
Try(
show(my_f2({1,2,3}));
,
show(exception_msg);
);
-Jarmo