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
lwx228
Level VIII

How to use JSL to extract formula text from a column and save it to a cell?

For example, add a "test" column with "Big Class.jmp" and write a random formula.How do use JSL to save the formula extract formula text in this column to a cell in another column?

 

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
New Column( "test" );
Column( "test" ) << Formula( If( age > 15, height + 50 + weight, height + 100 + weight ) );
dt << run formulas;


New Column( "txt", Character, "Nominal" );

2021-07-23_1827.png

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to use JSL to extract formula text from a column and save it to a cell?

You can get the formula with << Get Formula then change that to character and do required modifications

 

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << New Column("test", Formula(If(:age > 15, :height + 50 + :weight, :height + 100 + :weight)));

dt << New Column("txt", Character, "Nominal", << Set Each Value(
	Substitute(Char(AsColumn(:test) << get formula), " ", "")
));
-Jarmo

View solution in original post

9 REPLIES 9
lwx228
Level VIII

Re: How to use JSL to extract formula text from a column and save it to a cell?

And I want to use JSL to achieve the formula to remove the newline character, but also to remove redundant space.Makes the formula text content stored in the cell simpler.

 

dt[1,"txt"]=

If(:age>15,:height+50+:weight,:height+100+:weight)

Thanks Experts!

 

 

jthi
Super User

Re: How to use JSL to extract formula text from a column and save it to a cell?

You can get the formula with << Get Formula then change that to character and do required modifications

 

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << New Column("test", Formula(If(:age > 15, :height + 50 + :weight, :height + 100 + :weight)));

dt << New Column("txt", Character, "Nominal", << Set Each Value(
	Substitute(Char(AsColumn(:test) << get formula), " ", "")
));
-Jarmo
lwx228
Level VIII

Re: How to use JSL to extract formula text from a column and save it to a cell?

done with a Regular Expression

2021-07-23_1941.png

lwx228
Level VIII

Re: How to use JSL to extract formula text from a column and save it to a cell?

The prediction formula derived from xGBoost training is too complex.

 

How to apply this prediction formula to new data is really complicated.

txnelson
Super User

Re: How to use JSL to extract formula text from a column and save it to a cell?

See << get formula to retrieve the formula.

See Word() to retrieve the blank delimited elements to build a "blank removed" version of the formula or it can be done with a Regular Expression

 

 

Jim
ian_jmp
Level X

Re: How to use JSL to extract formula text from a column and save it to a cell?

It depends on what the ultimate intention is here, but it might be more straightforward to persist the formula in cell of an expression column.

lwx228
Level VIII

Re: How to use JSL to extract formula text from a column and save it to a cell?

Yes, my use is to train the pattern once, get the prediction formula, and directly save the formula in text form in the cell.
When used for new data analysis, use the following form directly to calculate the new data using the original prediction formula

aaa = dt[1, "txt"];

Current Data Table( d2 );
Eval( Parse( "Column(d2,\!"test\!")<<Formula(" || aaa || ")" ) );
d2 << run formulas;
Column( "test" ) << deleteFormula;

Thanks!

lwx228
Level VIII

Re: How to use JSL to extract formula text from a column and save it to a cell?

I'm still unfamiliar with using JSL for regular processing,
Again, this is done with the EmEditor.

document.selection.Replace("([a-Z]) ([a-Z])","\\1zzzz\\2",eeReplaceAll | eeFindReplaceRegExp,eeExFindSeparateCRLF);
document.selection.Replace(" ","",eeReplaceAll | eeFindReplaceRegExp,eeExFindSeparateCRLF);
document.selection.Replace("zzzz"," ",eeReplaceAll | eeFindReplaceRegExp,eeExFindSeparateCRLF);
document.selection.Replace("Is Missing\\(:(.[^)]{0,})\\)\\|","",eeReplaceAll | eeFindReplaceRegExp,eeExFindSeparateCRLF);
document.selection.Replace("!Is Missing\\(:(.[^)]{0,})\\)&","",eeReplaceAll | eeFindReplaceRegExp,eeExFindSeparateCRLF);
lwx228
Level VIII

Re: How to use JSL to extract formula text from a column and save it to a cell?

Since there are no missing values in the actual data, all of the following forms of code can be removed.

!Is Missing(:abc) &
Is Missing(:abb) |


How should this be coded in JSL?Thanks Experts!