Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
lwx228
Level VII

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

 

2018-09-14_22-39-33.png

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
uday_guntupalli
Level VIII

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

View solution in original post

Highlighted
txnelson
Super User

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

View solution in original post

4 REPLIES 4
Highlighted
uday_guntupalli
Level VIII

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

View solution in original post

Highlighted
lwx228
Level VII

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!
Highlighted
txnelson
Super User

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

View solution in original post

Highlighted
lwx228
Level VII

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!
Article Labels

    There are no labels assigned to this post.