cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
PowerOx327
Level I

How do I manipulate column formulae in data tables by scripting?

Hi, 

 

I'm trying to add a formula to convert values in a selected column through scripting without having to add any new columns in the data table, is there a way to edit formulas for a column by scripting? For example I'm trying to set the height column in this data table to be halved when I run the script:

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
Current Data Table() << Get Column Names;
height = height/2;
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How do I manipulate column formulae in data tables by scripting?

Your specified formula is recursive when used as a column formula.  A column formula will run whenever it detects a change in the column.

What you are suggesting can simply be done in open JSL.

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
Current Data Table() << Get Column Names;
height = height/2;

or

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
For( i = 1, i <= N Rows( current data table() ), i++,
	:height[i] = :height[i] / 2
);

or

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt:Height << set values( dt[0, 4] / 2 );

If the formula isn't recursive, one can set the column formula by using the Set Formula message

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
Current Data Table() << Get Column Names;
:height << set formula(:weight/2);

I strongly suggest that you take the time to read the Scripting Guide available in the JMP Documentation Library under the Help pull down menu

Jim

View solution in original post

2 REPLIES 2

Re: How do I manipulate column formulae in data tables by scripting?

A data column formula is just a JSL expression that is evaluated row-wise. You can use the data column messages << Get Formula() and << Set Formula(). Use expression functions to access and modify the expressions as needed.

txnelson
Super User

Re: How do I manipulate column formulae in data tables by scripting?

Your specified formula is recursive when used as a column formula.  A column formula will run whenever it detects a change in the column.

What you are suggesting can simply be done in open JSL.

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
Current Data Table() << Get Column Names;
height = height/2;

or

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
For( i = 1, i <= N Rows( current data table() ), i++,
	:height[i] = :height[i] / 2
);

or

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt:Height << set values( dt[0, 4] / 2 );

If the formula isn't recursive, one can set the column formula by using the Set Formula message

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
Current Data Table() << Get Column Names;
:height << set formula(:weight/2);

I strongly suggest that you take the time to read the Scripting Guide available in the JMP Documentation Library under the Help pull down menu

Jim