cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to move from signal modeling to system modeling at the first JMP Aerospace Analytics webinar. Register. June 18, 1 p.m. US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
JMPuser17
Level I

access column values in a formula in a loop

I want to write a script to create a new column for each column present in the original table; the new column values equal a constant value subtracted from the original column values. How do I access the values in the column?  The 'cnme' reads the column references accurately but Column(cnme) does not read the values in the column

 

Code:


a = N Col( Data Table( "vert" ) );

For( i = 2, i <= a, i++,
cnme = Column( i ) << get name;
New Column( "col", Formula(Subtract(Column(cnme), 6.5) ) ) );

1 REPLY 1
txnelson
Super User

Re: access column values in a formula in a loop

A column formula needs to be fully expanded into the full JSL statement, because otherwise if the values will change as the variables referenced in the formula is changed as additional columns are specified.  In your case, the variable cnme changes multiple times.  See below for a couple examples of how to work abound this.

Names Default To Here( 1 );

a = N Col( Data Table( "vert" ) );

For( i = 2, i <= a, i++,
	cnme = Column( i ) << get name;
	Eval(
		Substitute(
				Expr(
					New Column( "Adjusted " || cnme, Formula( Subtract( As Column( _cnme_ ), 6.5 ) ) )
				),
			Expr( _cnme_ ), cnme
		)
	);
);
Names Default To Here( 1 );

a = N Col( Data Table( "vert" ) );

For( i = 2, i <= a, i++,
	cnme = Column( i ) << get name;
	Eval( Eval Expr( New Column( "Adjusted " || cnme, Formula( Subtract( As Column( Expr( cnme ) ), 6.5 ) ) ) ) );
);
Jim

Recommended Articles