cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
spudton
Level III

Concatenate strings to create variables within a formula

Hi,

beginner JMP user here,

I would like to create a new column "Tag Range" which has the formula in it "Tag.ULIMIT-Tag.LLIMIT".

Tag.ULIMIT and Tag.LLIMIT are columns in my data table.

I can create the column by explicitly defining the column names in the formula as below, but I would like to replace these with the variables "UpperLIMIT" and "LowerLIMIT".

(ultimately, I would like to run a script that creates this column based on the tag name selected by the user)

 

 

Names Default To Here( 1 );
a = "Tag";

UpperLIMIT = a || ".ULIMIT";
LowerLIMIT = a || ".LLIMIT";

dt = Current Data Table();

 

This works:

dt << New Column( a || " Range", formula( :Tag.ULIMIT - :Tag.LLIMIT ) );

 

this doesn;t work:

dt << New Column( a || " Range", formula( :UpperLIMIT - :LowerLIMIT ) );
1 REPLY 1
txnelson
Super User

Re: Concatenate strings to create variables within a formula

JMP does not evaluate the statements within a "formula" definition prior to creating the formula.  It assumes the formula is as it needs to be.  Therefore the formula needs to be syntactically as needed when specified.  The code below handles that for your example

Names Default To Here( 1 );
dt = Current Data Table();

a = "Tag";

UpperLIMIT = a || ".ULIMIT";
LowerLIMIT = a || ".LLIMIT";

Eval(
	Parse(
		"dt << New Column( \!"" || a || " Range\!", formula( :"
		 || UpperLIMIT || " - :" || LowerLIMIT || " ) )); "
	)
);
Jim