cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use to use Text Explorer to glean valuable information from text data at April 25 webinar.
Choose Language Hide Translation Bar
View Original Published Thread

Getting formula from column in a pretty format

FN
FN
Level VI

I would like to obtain the formula of each column in a more readable format (also called pretty format).

 

For the example below I will like to obtain "height / weight".

 

Simply removing ":" will not work as columns can have such character.

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
col = New Column( "Ratio" );
col << Set Formula( :height / :weight );
col << Eval Formula;
result = col << Get Formula;
Show( result );

 // result = :height / :weight;

 

// desired_result = "height / weight";

 

5 REPLIES 5
txnelson
Super User

Re: Getting formula from column in a pretty format

Here is an example on how to do that

formula.PNG

names default to here(1);
dt=open("$SAMPLE_DATA\big class.jmp");
dt<< new column("Example", formula(sqrt(:Height/:Age+:Weight*:Height)));

new window("pretty", expr as picture(dt:Example << get formula));

 

Jim
FN
FN
Level VI

Re: Getting formula from column in a pretty format

How would I obtain a string that reads the following in your example?
"sqrt(Height/Age + Weight*Height))"

Is there any 'expr as formula'?
txnelson
Super User

Re: Getting formula from column in a pretty format

Try this

names default to here(1);
dt=open("$SAMPLE_DATA\big class.jmp");
dt<< new column("Example", formula(sqrt(:Height/:Age+:Weight*:Height)));

charFormula = char(dt:Example << get formula);
substitute into(charFormula,
	expr(":"), expr(" ")
);show(charFormula);
Jim
FN
FN
Level VI

Re: Getting formula from column in a pretty format

The main limitation is that I might have ":" in the name that is not due to the formula.
mzwald
Staff


Re: Getting formula from column in a pretty format

JSL syntax requires colons to refer to columns, but there are other options such as what I show here.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Column( "Ratio", Set Formula( ascolumn("height") / ascolumn("weight")));

Not sure if it's more pretty though