I'm trying to add new column formula to a table based on user input. The input can either be a single value or a column selection.
Been trying couple methods but I couldn't get one which could handle this interchangeably.
Sample script that I tried below.
Ideally I can keep the "newcolexpr" expression the same regardless of the input. This is mainly because I'm trying to deploy custom formula column which takes lots of inputs (i.e. >8 inputs)
Appreciate the help.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
//when selection is a single value
//desired outcome: a new column "Test" with formula (1*5)
selection = {1};
newcolexpr = expr(
dt << new column("Test", formula(expr(selection[1])*5))
);
eval(eval expr(newcolexpr));
//when selection is a column (e.g. "height")
//desired outcome: a new column "Test" with formula ("height"*5)
selection = {"height"};
newcolexpr = expr(
dt << new column("Test", formula(expr(selection[1])*5))
);
eval(eval expr(newcolexpr));