Below are few examples what you could do. There are more simple (easier to understand) looking ways of filtering the found columns, but associative arrays are good for this type of use case
Names Default To Here(1);
dt = New Table("Untitled 3",
Add Rows(1),
Compress File When Saved(1),
New Column("Column 1", Numeric, "Continuous", Set Values([1,2,3,.])),
New Column("Column 2", Numeric, "Continuous", Set Values([2,3,4,5])),
New Column("Column 3", Numeric, "Continuous", Set Values([3,4,5,.]))
);
col_list = {"Column 1", "Column 2", "Column 3", "Column 4"};
table_col_list = dt << Get Column Names("String");
// keep only columns which are found from data table
cols_to_keep = Associative Array(col_list);
cols_to_keep << Intersect(Associative Array(table_col_list));
cols_to_keep = cols_to_keep << get keys;
// if you don't need a formula, data table subscripting is quite easy solution
dt << New Column("SumForCols", Numeric, Continuous, << Set Each Value(
Sum(dt[Row(), cols_to_keep]);
));
// if you do need a formula, you can build one with expressions (requires JMP16+ due to For Each usage)
// https://community.jmp.com/t5/JSL-Cookbook/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998
f_expr = Expr(Sum());
For Each({col_name}, cols_to_keep,
Insert Into(f_expr, Name Expr(AsColumn(col_name)));
);
show(name expr(f_expr));
Eval(EvalExpr(
dt << New Column("SumForColsFormula", Numeric, Continuous, Formula(
Expr(name expr(f_expr));
))
));
First I calculate which columns exist in the data table from the wanted list by using associative arrays and intersect. Then there are two options, using << set each value and data table subscripting to calculate the sum or building formula expression and using that
-Jarmo