BookmarkSubscribe
Choose Language Hide Translation Bar
Highlighted

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

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

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

@lwx228,
Try the following.

dt = Current Data Table();

Column("age") << formula(As Column(column(dt,4)) + As Column(column(dt,5)));
Best
Uday

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

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

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

@lwx228,
Try the following.

dt = Current Data Table();

Column("age") << formula(As Column(column(dt,4)) + As Column(column(dt,5)));
Best
Uday

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!

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

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

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!