cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar

I am generating new column based on a user input and need to move

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

ConfidenceOwl94_1-1764711851309.png

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) ) );
3 ACCEPTED SOLUTIONS

Accepted Solutions

Re: I am generating new column based on a user input and need to move

I'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 ) )
);

View solution in original post

txnelson
Super User

Re: I am generating new column based on a user input and need to move

Here 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 || ") );"
	)
);
Jim

View solution in original post

jthi
Super User

Re: I am generating new column based on a user input and need to move

I 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 <<Move Selected Column

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))
);
-Jarmo

View solution in original post

4 REPLIES 4

Re: I am generating new column based on a user input and need to move

I'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 move

This 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 ) )
);
txnelson
Super User

Re: I am generating new column based on a user input and need to move

Here 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 || ") );"
	)
);
Jim
jthi
Super User

Re: I am generating new column based on a user input and need to move

I 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 <<Move Selected Column

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))
);
-Jarmo

Recommended Articles