cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
lwx228
Level VIII

How to automatically extract the column name used by the formula in the JSL code?

How to use JSL to automatically extract from a JSL formula the column names used by the formula, and group them into a combination.


For example, in the image of 1, automatically extract the column name to get a combination of 2.

Thanks!

dt = Current Data Table();
dt << New Column( "text", formula( :K36 >= 71.93 & :XA >= -32.3 & :a1 >= -43.67 & :A56 < 18.9 ) );
dt << run formulas;
Column( "text" ) << deleteFormula;

 

2020-05-25_15-56.png

1 ACCEPTED SOLUTION

Accepted Solutions
Georg
Level VII

Re: How to automatically extract the column name used by the formula in the JSL code?

probably this script does the Job for you:

// generate a table
dt = New Table( "testdata",
	add rows( 3 ),
	New Column( "K36", Continuous, set values( [70, 80, 90] ) ),
	New Column( "XA", Continuous, set values( [30, 32, 33] ) ),
	New Column( "a1", Continuous, set values( [-50, -40, -30] ) ),
	New Column( "A56", Continuous, set values( [10, 20, 10] ) )
);

// add a formula
dt << New Column( "f1", formula( :K36 >= 71.93 & :XA >= -32.3 & :a1 >= -43.67 & :A56 < 18.9 ) );
dt << run formulas;

// get formula, convert to string and split words
formula = dt:f1 << get formula;
formula_txt_words = Words( Char( Name Expr( formula ) ) );

// search for column names in words and put it into list
columns_lst = {};
For( i = 1, i <= N Arg( formula_txt_words ), i++,
	If( Starts With( formula_txt_words[i], ":" ),
		Insert Into( columns_lst, Substitute( formula_txt_words[i], ":", "" ) )
	)
);
Show( columns_lst );

// Group columns
dt << group columns( "Cols used by f1", columns_lst );
// Column( "text" ) << deleteFormula;
Georg

View solution in original post

2 REPLIES 2

Re: How to automatically extract the column name used by the formula in the JSL code?

You would have to traverse the arguments of the expression used for the formula, identify the columns, and store them in a list.

 

Please see JMP Help > JMP Documentation Library > Scripting Guide > Chapter 8: Lists and Expressions

Retrieve a Stored Expression Rather than its Result section. The concepts and the necessary and supporting functions are fully described and demonstrated.

Georg
Level VII

Re: How to automatically extract the column name used by the formula in the JSL code?

probably this script does the Job for you:

// generate a table
dt = New Table( "testdata",
	add rows( 3 ),
	New Column( "K36", Continuous, set values( [70, 80, 90] ) ),
	New Column( "XA", Continuous, set values( [30, 32, 33] ) ),
	New Column( "a1", Continuous, set values( [-50, -40, -30] ) ),
	New Column( "A56", Continuous, set values( [10, 20, 10] ) )
);

// add a formula
dt << New Column( "f1", formula( :K36 >= 71.93 & :XA >= -32.3 & :a1 >= -43.67 & :A56 < 18.9 ) );
dt << run formulas;

// get formula, convert to string and split words
formula = dt:f1 << get formula;
formula_txt_words = Words( Char( Name Expr( formula ) ) );

// search for column names in words and put it into list
columns_lst = {};
For( i = 1, i <= N Arg( formula_txt_words ), i++,
	If( Starts With( formula_txt_words[i], ":" ),
		Insert Into( columns_lst, Substitute( formula_txt_words[i], ":", "" ) )
	)
);
Show( columns_lst );

// Group columns
dt << group columns( "Cols used by f1", columns_lst );
// Column( "text" ) << deleteFormula;
Georg