cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
tangxu
Level II

script to add two column

i am trying to add two columns. 

two of the column has name abcd and efgh

 

following line works:

 

dt_tab << New Column( newcolumn, formula( :name( "abcd" ) + :name( "efgh" ) ) );

 

but following code is throwing an error

 

 

name1 = "abcd";
name2 ="efgh";

dt_tab << New Column( name1 || "3", formula(:name(name1) + :name(name2)));

 

 

why is the 2nd method not working? 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: script to add two column

My error......I had placed an ")" wrong, and should have used the As Column() function, not the Column() function

Names Default To Here( 1 );
dt_tab = New Table( "Example",
	Add Rows( 4 ),
	New Column( "abcd", 

		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [1, 2, 3, 4] )
	),
	New Column( "efgh",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [5, 6, 7, 8] )
	)
);

name1 = "abcd";
name2 = "efgh";

Eval(
	Substitute(
			Expr(
				dt_tab <<
				New Column( name1 || "3",
					formula(
						As Column( __name1__ )
						+As Column( __name2__ )
					)
				)
			),
		Expr( __name1__ ), name1,
		Expr( __name2__ ), name2
	)
);
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: script to add two column

The reason this is not working, is that neither the :Name() function nor the Formula() element does not parse the contents of the function before execution.  You need to create the exact JSL before execution

name1 = "abcd";
name2 = "efgh";

Eval(
	Substitute(
			Expr(
				dt_tab << New Column( name1 || "3",
					formula( Column( __name1__ ) ) + Column( __name2__ )
				)
			),
		Expr( __name1__ ), name1,
		Expr( __name2__ ), name2
	)
);

 

Jim
tangxu
Level II

Re: script to add two column

Thank you Jim. I tried this but still not working. 

txnelson
Super User

Re: script to add two column

My error......I had placed an ")" wrong, and should have used the As Column() function, not the Column() function

Names Default To Here( 1 );
dt_tab = New Table( "Example",
	Add Rows( 4 ),
	New Column( "abcd", 

		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [1, 2, 3, 4] )
	),
	New Column( "efgh",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [5, 6, 7, 8] )
	)
);

name1 = "abcd";
name2 = "efgh";

Eval(
	Substitute(
			Expr(
				dt_tab <<
				New Column( name1 || "3",
					formula(
						As Column( __name1__ )
						+As Column( __name2__ )
					)
				)
			),
		Expr( __name1__ ), name1,
		Expr( __name2__ ), name2
	)
);
Jim