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
- :
- How do replace the column name with the column number in the formula?

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

Highlighted

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

Sep 12, 2018 7:49 AM
(2282 views)

Just take this table as an example:

The formula for column 2 is the sum of column 4 plus column 5

How to replace "age", "height" and "weight" in the following code with 2, 4 and 5 respectively?Thank you very much!

dt = Current Data Table();

Column( "age" ) << Formula( :height + :weight );

2 ACCEPTED SOLUTIONS

Accepted Solutions

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

@lwx228,

Try the following.

```
dt = Current Data Table();
Column("age") << formula(As Column(column(dt,4)) + As Column(column(dt,5)));
```

Best

Uday

Uday

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

The reference to the data table pointer "dt" will fail, unless it is available in the JMP session....so in other words, the formula may not work when you open the data table in a new jmp session....or it may be wrong in the new session, if "dt" points to a different data table. Therefore, the reference needs to be added to the formula, so it is there for you to use:

`Column(dt,6) << formula(dt=current data table(); As Column(dt,4) + As Column(dt,5));`

Note, the formula is also changed. The Column() reference has been removed, since it is redundent.

Also, since the formula know what data table it is pointing to, you can actually reduce the formula to:

`Column(dt,6) << formula(As Column(4) + As Column(5));`

Jim

4 REPLIES 4

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

@lwx228,

Try the following.

```
dt = Current Data Table();
Column("age") << formula(As Column(column(dt,4)) + As Column(column(dt,5)));
```

Best

Uday

Uday

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

Re: How do replace the column name with the column number in the formula?

Column(dt,2) << formula(As Column(column(dt,4)) + As Column(column(dt,5)));

Tried it, learned it. Thank you very much!

Tried it, learned it. Thank you very much!

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

The reference to the data table pointer "dt" will fail, unless it is available in the JMP session....so in other words, the formula may not work when you open the data table in a new jmp session....or it may be wrong in the new session, if "dt" points to a different data table. Therefore, the reference needs to be added to the formula, so it is there for you to use:

`Column(dt,6) << formula(dt=current data table(); As Column(dt,4) + As Column(dt,5));`

Note, the formula is also changed. The Column() reference has been removed, since it is redundent.

Also, since the formula know what data table it is pointing to, you can actually reduce the formula to:

`Column(dt,6) << formula(As Column(4) + As Column(5));`

Jim

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

Re: How do replace the column name with the column number in the formula?

dt = Current Data Table();

Column(dt,2)<< formula(As Column(4) + As Column(5));

thank you!

Column(dt,2)<< formula(As Column(4) + As Column(5));

thank you!