I am generating new column based on a user input and need to moveI am generating new column based on a user input and need to move using script. Can anyone help to fix my script

dt << New Column("Suspected "|| selectedCol,
Formula(
If(Contains(myValueList, char(as column(selectedCol))),
"Yes",
"No"
)
)
);
Data Table( dt ) << Move Selected Columns( as column("Suspected "|| selectedCol), after( as column(selectedCol) ) );Basic Data Analysis and ModelingRe: I am generating new column based on a user input and need to moveI'm able to get it to work by enclosing As Column() in a Name Expr() and putting it in a list.
dt << Move Selected Columns(
{Name Expr( As Column( "Suspected " || selectedCol ) )},
After( As Column( selectedCol ) )
);
Re: I am generating new column based on a user input and need to moveThis way works, too, with only the string in a list, but the After() has to have As Column().
dt << Move Selected Columns(
{"Suspected " || selectedCol},
After( As Column( selectedCol ) )
);Re: I am generating new column based on a user input and need to moveHere is how I got it to work
dt << New Column( "Suspected " || selectedCol,
Character,
Formula(
If( Contains( myValueList, Char( As Column( selectedCol ) ) ),
"Yes",
"No"
)
)
);
Eval(
Parse(
"dt << Move Selected Columns(:Suspected " || selectedCol || ", after( :" ||
selectedCol || ") );"
)
);
Re: I am generating new column based on a user input and need to moveI would strongly suggest adding expression evaluation to your column to avoid possible issues (compare how my formula vs your formula looks like). You can also get reference to the created column and use that with <
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
selectedCol = "age";
myValueList = {"12", "15"};
newcol = Eval(EvalExpr(
dt << New Column("Suspected "|| selectedCol, Character, Nominal, Formula(
If(Contains(Expr(myValueList), Char(Expr(NameExpr(As column(dt, selectedCol))))),
"Yes",
"No"
)
));
));
dt << Move Selected Columns(
newcol, After(Eval(selectedCol))
);