Subscribe Bookmark RSS Feed

Add new column with formula to data table at certain position

gandi2223

Community Trekker

Joined:

Oct 1, 2014

Is it possible to add a new column to a data table (a) at a certain position (e.g. after a particular column) and (b) assign it a formula?

The New Column command can do (a) and the Add Multiple Columns command can do (b), but is there a way to get both done in one go?

Something like the command below (which does not give the desired result, however):

dt << New Column( "NewCol",

  After(:Col3),

  Numeric,

  Continuous,

  Format( "Best", 5 ),

  Formula( :Col3 * 2 )

);

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

I think you need a couple of steps:

dt = Open("$SAMPLE_DATA/Big Class.jmp");

WAit(2);

dt << NewColumn("BMI", Numeric, Continuous, Formula(:weight/:height^2));

Wait(2);

dt << MoveSelectedColumns({:BMI}, After(:sex));

3 REPLIES
Solution

I think you need a couple of steps:

dt = Open("$SAMPLE_DATA/Big Class.jmp");

WAit(2);

dt << NewColumn("BMI", Numeric, Continuous, Formula(:weight/:height^2));

Wait(2);

dt << MoveSelectedColumns({:BMI}, After(:sex));

mdawson69

Community Trekker

Joined:

Aug 26, 2015

I think you have your a and b mixed up. Add Multiple Columns permits you to add the new columns at a specific point relative to other columns—Before First, After Last, or after a select column—and is otherwise quite limited with what you can preset for the new columns. New Column will permit you to set any number of column properties such as a formula, but lacks a parameter for placement. As Ian suggested, the way to achieve what you want is to define the new column using New Column then use Move Selected Columns to place the column in the data table.

gandi2223

Community Trekker

Joined:

Oct 1, 2014

True!