Subscribe Bookmark RSS Feed

JSL: How to copy a formula from one data table to another?

jumper

Community Trekker

Joined:

Oct 7, 2014

I need to copy a formula from one data table to another.

The only suggestion I found and managed to get to work is this:

Copy Columns With Formulas


The easiest way is to get the script for the original data table.



data table("Original") << get script;



Now the script appears in the log.  Just copy and paste into a new script, keeping only the bits related to adding the the formula columns. 


which seems, however, very convoluted and time-consuming when I need to apply it multiple times.

This other method was suggested here: Saving the prediction formula to an existing column?


f = column("prednew") << Get Formula;


column("predold") << Set Formula( Name Expr( f ));


so I tried:


f = data table("table 1") << column("my formula") << Get Formula;


data table("table 2") << column("my formula") << Set Formula( Name Expr( f ));


where 'my formula' already exists, but is empty, in table 2

but it doesn't work, and the log gives no errors.

Any ideas? Is this documented anywhere in JMP's official documentation?

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Get Formula() and Set Formula() are documented, whereas your syntax is probably not. Column() cannot be used as a message to a data table. Use instead the first argument of Column() to specify the data table.

f = Column( Data Table( "table 1" ), "my formula" ) << Get Formula;

Column( Data Table( "table 2" ), "my formula" ) << Set Formula( Name Expr( f ) );

3 REPLIES
Solution

Get Formula() and Set Formula() are documented, whereas your syntax is probably not. Column() cannot be used as a message to a data table. Use instead the first argument of Column() to specify the data table.

f = Column( Data Table( "table 1" ), "my formula" ) << Get Formula;

Column( Data Table( "table 2" ), "my formula" ) << Set Formula( Name Expr( f ) );

jumper

Community Trekker

Joined:

Oct 7, 2014

I couldn't get the method in your other post to work, but this works perfectly - thank you.

ms

Super User

Joined:

Jun 23, 2011

Another option is to use Get Column Properties() followed by Add Column Properties() to copy all properties, incl. formula. No need for Name Expr() when using this approach.

oldcol = Column( Data Table( "table 1" ), "my formula" );

newcol = Column( Data Table( "table 2" ), "my formula" );

newcol << Add Column Properties( oldcol << Get Column Properties() );