turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Editing a formula in JMP script

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Nov 7, 2017 8:46 PM
(1068 views)

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 ) );
```

Solved! Go to Solution.

2 ACCEPTED SOLUTIONS

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Nov 7, 2017 10:17 PM
(1806 views)

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 ) ) );
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Nov 8, 2017 2:03 AM
(1789 views)

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));
```

7 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Nov 7, 2017 9:40 PM
(1059 views)

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 ) );
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Nov 7, 2017 9:47 PM
(1056 views)

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"

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Nov 7, 2017 10:17 PM
(1807 views)

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 ) ) );
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Nov 8, 2017 2:01 AM
(1035 views)

See below.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Nov 8, 2017 2:03 AM
(1790 views)

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));
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Nov 8, 2017 10:55 AM
(1005 views)

Awesome!! Thanks ian !!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Nov 8, 2017 10:55 AM
(1004 views)

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