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
- :
- 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
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Nov 7, 2017 8:46 PM
(696 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 ) );
```

2 ACCEPTED SOLUTIONS

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Solution

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
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Solution

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
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Nov 7, 2017 9:40 PM
(687 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
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Nov 7, 2017 10:17 PM
(1314 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
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Nov 8, 2017 2:03 AM
(1297 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
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Awesome!! Thanks ian !!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

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