You could do something like this.
Names default to here(1);
dt = open("$SAMPLE_DATA\Big Class.jmp");
dt << New Column("Cpk", Set Each Value(random normal(1, 1)));
dt << New Column("1.0<=CpK <1.33", Set Each Value(0));
col_names = dt << Get column names(string); // this is your existing columns
//I would just do a not contains which checks where an item is in a list, returning 0 if it doesn't
if(!Contains(col_names, "CpK<1.0"),
dt << New Column( "CpK<1.0", numeric,
formula(
// you also don't have to do the if(thing, 1, 0) :Cpk < 1 will resolve to 1 and 0 anyway
:Cpk < 1
)
)
);
// this one shouldn't get remade
if(!Contains(col_names, "1.0<=CpK <1.33"),
dt << New Column( "1.0<=CpK <1.33", numeric, formula( 1.0<=:Cpk <1.33 ))
);
if(!Contains(col_names, "1.33<=CpK<1.67"),
dt << New Column( "1.33<=CpK<1.67", numeric, formula( 1.33<=:Cpk <1.67 ))
);
if(!Contains(col_names, "1.67<=CpK<2.0"),
dt << New Column( "1.67<=CpK<2.0", numeric, formula( 1.67<=:Cpk <2 ))
);
if(!Contains(col_names, "CpK>=2.0"),
dt << New Column( "CpK>=2.0", numeric, formula( 2.0<=:Cpk ))
);
You could also abstract it a little so you can change only 1 data structure and it would change your fields.
//But I would probably do it another way
Names default to here(1);
dt = open("$SAMPLE_DATA\Big Class.jmp");
dt << New Column("Cpk", Set Each Value(random normal(1, 1)));
dt << New Column("1<=Cpk<1.33", Set Each Value(0));
col_names = dt << Get column names(string); // this is your existing columns
//I'd make a 2 col matrix with low and high check then make the columns dynamically
cpk_check = [. 1, 1 1.33, 1.33 1.67, 1.67 2, 2 .];
for(i=1, i<=nrows(cpk_check), i++,
low = cpk_check[i, 1];
high = cpk_check[i, 2];
if(!ismissing(low),
if(!ismissing(high),
col_name = char(low) || "<=Cpk<" ||char(high);
f = EvalExpr(Expr(low)<=:Cpk<Expr(high));
, //else high is missing
col_name = char(low) || "<=Cpk";
f = EvalExpr(Expr(low)<=:Cpk);
)
, //else
if(!ismissing(high),
col_name = "Cpk<" ||char(high);
f = EvalExpr(:Cpk<Expr(high));
, //else high is missing
//assuming you don't want this
throw("high and low values can't both be missing")
);
);
show(col_name, nameexpr(f));
if(!Contains(col_names, col_name),
Eval(EvalExpr(dt << New Column( col_name, numeric, formula( Expr(nameexpr(f)) )) ));
);
)