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

Showing results for

- JMP User Community
- :
- Discussions
- :
- Trying to add last 4 columns together based on var...

- 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 8, 2012 2:20 PM
(380 views)

Hi there, I have a DT that is imported into jmp and what I am trying to create a formula to add the last 4 columns together. This is fine if the names where static and the dt had the same amount of columns but unfortunalty thiis is not the case.

The DT could have 7 to 10 columns dependent on the raw data pull and the column names are also variable. My question would be, is it possible to just create a formula for these last 4 columns and add them together, even if i didnt know the column names.

I have got the following to add specific columns:

/*Set Variables to the column locations */

a = column name **(****14)**;

b = column name **(****15)**;

c = column name **(****16)**;

d = column name **(****17)**;

/* Create a new column and add the 4 column variables together */

NewColumn**(**"ADD_LST_4",Numeric,Formula**(**a**[]**+b**[]**+c**[]**+d**[])**,EvalFormula**)**;

Where i am falling down to to choose the last 4 columns and not the specific locations

any ideas?

Rgds

Lodey

1 REPLY

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

Oct 8, 2012 3:15 PM
(261 views)

To get a column variable from column number you can use *a = Column(1)*.

Here is one way to do it by script, although i think there may exist a more elegant way.

dt = Open**(** "$SAMPLE_DATA/Baltic.jmp" **)**;

col = **(**dt << get column names**())[**N Col**(** dt **)** - **3** :: N Col**(** dt **)]**; //list of last 4 columns

dt << New Column**(** "Sum", numeric **)**;

For Each Row**(** :Sum**[]** = Sum**(** Column**(** col**[****1****]** **)[]**, Column**(** col**[****2****]** **)[]**, Column**(** col**[****3****]** **)[]**, Column**(** col**[****4****]** **)[]** **)** **)**;