Adding Formula Columns based on Column Name ListHi there! I'm trying to create a script that will generate Formula columns based on if a Column Name contains the right keyword. I think I'm misusing the way lists translate strings into other functions. Currently using JMP 17
Ptable = Current Data Table ();
col list = Ptable << Get Column Names(String);
if(debug == 1, Print(col list));
For(i=1, i<NCOLS></NCOLS>
Automation and ScriptingRe: Adding Formula Columns based on Column Name ListYou have to evaluate column correctly there. Expr(NameExpr(AsColumn())) is one option
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
mycol1 = "height";
mycol2 = "weight";
Eval(EvalExpr(
new_col = dt << New Column("Col", numeric, continuous, formula(
Expr(NameExpr(AsColumn(dt, mycol1))) * Expr(NameExpr(AsColumn(dt, mycol2)))
))
));
show(new_col << get formula);
Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute
Re: Adding Formula Columns based on Column Name ListNevermind! Issue was with my array clist not pulling the column names into a list!
@jthi Does naming a column also require an Expression Eval? The page you shared showed a Concat with Char( Array[#] ) working just fine, but I get an error trying to rename columns, code shown below. I'm not adding columns, so I'm not sure why there would be a mismatch between the N Cols and the counter in the For loop.
clist = Ptable << Get Column Names( String );
num_col = N Cols(Ptable);
For(i=3, i < num_col, i++,
Column(i) << Set Name(Char(clist[i]) || " °C"); //Error on this line
);
"Subscript Range in access or evaluation of 'clist[ /*###*/i]' , clist[/*###*/i]"