turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Add new column with formula to data table at certa...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 5, 2015 6:36 AM
(3212 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 5, 2015 10:45 AM
(2775 views)

*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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 5, 2015 11:01 AM
(2775 views)