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
akrishna39
Level III

Editing a formula in JMP script

Hi,

I have a very long formula stored in a variable named f. Now, I have to create a new column where I paste the formula b0 + b1*f. If I do it the following way, it works, but when I try to see the formula by right clicking on the column, I see " b0 + b1*f " as my formula. I wanted to see the expression of f stored in 'f' in the formula and not just the letter 'f'. Please help. Thanks!!

 

test_data<<NewColumn("response_hat");
Column( Data Table( "test_data" ), "response_hat" ) << Set Formula( Name Expr( b0 + b1*f ) );

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Editing a formula in JMP script

Now I understand and yes that is a pain.  The easiest way is probably to convert them back to strings as in h, below.  You can also do it with expressions, as in j.

dt = Open("$SAMPLE_DATA/iris.jmp");

f = Expr( 1 + 2 );
g = Expr( 1 + 2 + 3 );
h = parse(char(name expr(f)) || " + " || char(name expr(g)));
i = Expr( Expr(Name Expr(f)) + Expr(Name Expr(g)));
j = Eval Expr(i);

dt << New Column( "new", formula( name expr( f ) ) );
Column( dt, "new" ) << Set Formula( name expr( g ) );
dt << New Column( "from string", formula( name expr( h ) ) );
dt << New Column( "from expression", formula( name expr( j ) ) );

View solution in original post

ian_jmp
Level X

Re: Editing a formula in JMP script

Please find an alternative:

Names default to here(1);

f = Expr( 1 + 2 );
g = Expr( 1 + 2 + 3 );
h = Substitute(Expr(A + B), Expr(A), NameExpr(f), Expr(B), NameExpr(g));

dt = NewTable("Sum", NewColumn("A+B", Numeric, Continuous, Formula(NameExpr(h))), AddRows(3));

View solution in original post

7 REPLIES 7
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Editing a formula in JMP script

The constants b0 and b1 inside Name Expr() are causing the problem.  That function needs a variable that contains an expression rather than an expression.  Try putting the entire formula inside f and then call Name Expr( f ):

 

dt = Open("$SAMPLE_DATA/iris.jmp");

f = Expr( 1 + 2 );
g = Expr( 1 + 2 + 3 );

dt << New Column( "new", formula( name expr( f ) ) );
Column( dt, "new" ) << Set Formula( name expr( g ) );
akrishna39
Level III

Re: Editing a formula in JMP script

Thanks ih. But my question is how to put entire formula inside f? For example, in your script, if you wanted to create a new column having the formula f+g, how will you do it? And if I right click on that new column, it should show me "1 + 2 + 1 + 2 + 3", instead of "f + g"

ih
Super User (Alumni) ih
Super User (Alumni)

Re: Editing a formula in JMP script

Now I understand and yes that is a pain.  The easiest way is probably to convert them back to strings as in h, below.  You can also do it with expressions, as in j.

dt = Open("$SAMPLE_DATA/iris.jmp");

f = Expr( 1 + 2 );
g = Expr( 1 + 2 + 3 );
h = parse(char(name expr(f)) || " + " || char(name expr(g)));
i = Expr( Expr(Name Expr(f)) + Expr(Name Expr(g)));
j = Eval Expr(i);

dt << New Column( "new", formula( name expr( f ) ) );
Column( dt, "new" ) << Set Formula( name expr( g ) );
dt << New Column( "from string", formula( name expr( h ) ) );
dt << New Column( "from expression", formula( name expr( j ) ) );
ian_jmp
Level X

Re: Editing a formula in JMP script

See below.

ian_jmp
Level X

Re: Editing a formula in JMP script

Please find an alternative:

Names default to here(1);

f = Expr( 1 + 2 );
g = Expr( 1 + 2 + 3 );
h = Substitute(Expr(A + B), Expr(A), NameExpr(f), Expr(B), NameExpr(g));

dt = NewTable("Sum", NewColumn("A+B", Numeric, Continuous, Formula(NameExpr(h))), AddRows(3));
akrishna39
Level III

Re: Editing a formula in JMP script

Awesome!! Thanks ian !!

akrishna39
Level III

Re: Editing a formula in JMP script

This is cool!! Thanks ih !!! :)