cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
pauldeen
Level VI

Name quote a strange column name

I'm trying to insert a column name into a fit model expression. For that I need to escape strange characters in column names to do that we use the :"name"n convention. So how do I go from a string column name to this format?

colListY = {"Plating Thickness (m\!"\!")"};
//This doesn't work
newcolumnref = eval insert("\[:"^colListY[1]^"n]\");

//Looking for this end result
:"Plating Thickness (m\!"\!")"n

Which I can then insert anywhere, for example:

insert into(expr(Y()), newcolumnref);

Anybody know of a robust way to do this?

22 REPLIES 22
XanGregg
Staff

Re: Name quote a strange column name

Can you elaborate on the "does not work" part? I tried versions back to JMP 15 and the following seems to work. Maybe I'm missing part of the issue.

Data Table( "Big Class" ):weight << Set Name( "weight\!"\!"" );

Fit Model(
	Y( Column( "weight\!"\!"" ) ),
	Effects( :age, :sex, :height ),
	Personality( "Standard Least Squares" ),
	Run()
);
txnelson
Super User

Re: Name quote a strange column name

Just for giggles, I took the code back to JMP 11.2.1 and it works great.

Jim
pauldeen
Level VI

Re: Name quote a strange column name

@XanGregg Now that I'm testing it with your code it works here as well. Let me investigate and see if I can share the failing example more completely...

pauldeen
Level VI

Re: Name quote a strange column name

After carefull testing and going back through a few of my scripts I have not been able to make it fail again. Thanks for checking!

pauldeen
Level VI

Re: Name quote a strange column name

@XanGregg Column formulas don't work this way and the special quoting methods does work:

 

colListY = {"Plating Thickness (m\!"\!")"};
dt = Open( "$sample_data/big class.jmp" );
dt:age << setname( colListY[1] );
eval(eval expr(dt << New Column( "test",
		Numeric,
		"Continuous",
		Format( "Fixed Dec", 12, 2 ),
		Formula( expr(column(colListY[1])) - :height ),
		Set Display Width( 78 )
	)));

It produces a function column in which the formula is:

 

 

Column( "Plating Thickness (m\!"\!")" ) -  /*###*/:height/*###*/

which does not evaluate.

 

This does:

WrapColumns = Function({ColName},{default local},
	ReturnList = {};
	If(is list(ColName),	
		For(i=1, i<=n items(ColName), i++,
			insert into(ReturnList, parse(":" || Log Capture( Print( ColName[i] ) ) || "n"))
		);
	,
		insert into(ReturnList, parse(":" || Log Capture( Print( ColName ) ) || "n"))
	);
	Return(ReturnList);
);

eval(eval expr(dt << New Column( "test2",
		Numeric,
		"Continuous",
		Format( "Fixed Dec", 12, 2 ),
		Formula( expr(WrapColumns(colListY)[1]) - :height ),
		Set Display Width( 78 )
	)));

Do you know a way to fix this with the column() system?

 

Craige_Hales
Super User

Re: Name quote a strange column name

(without trying it, so might be wrong)

Formula( column(expr(colListY[1])) - :height ),

I think you want the expr inside the column. That way the column function is evaluated later, using the string captured earlier.

Craige
pauldeen
Level VI

Re: Name quote a strange column name

That results in a column formula error for me

Craige_Hales
Super User

Re: Name quote a strange column name

colListY = {"Plating Thickness (m\!"\!")"};
dt = Open( "$sample_data/big class.jmp" );
dt:age << setname( colListY[1] );
Eval(
	Eval Expr(
		dt << New Column( "test",
			Numeric,
			"Continuous",
			Format( "Fixed Dec", 12, 2 ),
			Formula( Column( Expr( colListY[1] ) )[]  ),
			Set Display Width( 78 )
		)
	)
);

The empty [ ] tells JMP to evaluate the column for the current row. 

Building column formulas like this probably hides the underlying column dependencies from JMP's formula evaluator; see discussion. If you have formula columns depending on other formula columns, JMP may not be able to peer into this indirection to figure out what to evaluate first.

Craige
jmp_demo
Level II

Re: Name quote a strange column name

This is a great question!

I love JMP and JMP users!
jmp_demo
Level II

Re: Name quote a strange column name

This is a great question!

I love JMP and JMP users!