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
- :
- JSL: treat variable within "<< set formula" Formul...

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

Highlighted

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

Jan 11, 2017 9:35 AM
(2368 views)

I feel like there should be an easy way to do this but it is eluding me...

Example:

blockSize = 15; col<<set formula(Sequence(1,1000,1,blockSize));

After running script, view formula in datatable -- "blockSize" is still being used as the fourth input for Sequence().

I don't really want this, as I'm going to dynamically define blockSize inside a loop that changes for each column it iterates through. How do I get the datatable's formula to be "Sequence(1,1000,1,15)" instead of "Sequence(1,1000,1, blockSize)"?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

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

Jan 11, 2017 9:39 AM
(4723 views)

Solution

```
blockSize = 15;
Eval(
Substitute(
Expr( col << Set Formula( Sequence( 1, 1000, 1, bbb ) ) ),
Expr( bbb ),
blockSize
)
);
```

Learn it once, use it forever!

3 REPLIES

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

Jan 11, 2017 9:39 AM
(4724 views)

```
blockSize = 15;
Eval(
Substitute(
Expr( col << Set Formula( Sequence( 1, 1000, 1, bbb ) ) ),
Expr( bbb ),
blockSize
)
);
```

Learn it once, use it forever!

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

Jan 11, 2017 12:43 PM
(2349 views)

Somes I like to use command strings with variable replacement, especially when I need to use the same command more than once, and if the formula or expression has more than one variable.

dt = New Table( "Testit", Add Rows( 1500 ), New Column( "bbb", Numeric, "Continuous", Format( "Best", 12 ), ), New Column( "ccc", Numeric, "Continuous", Format( "Best", 12 ), ), ); cmdStr = "^curcol^ << set formula(Sequence(1,1000,1,^blocksize^));"; curcol = ":bbb"; blocksize = 15; eval(parse(evalInsert(cmdStr))); // Eval Insert substitutes the variable values delimited by ^ // Parse converts the string to an expression // Eval runs the expression // uncomment the next line to see results of evalInsert // show(evalInsert(cmdStr) ); //==can reuse=== curcol =":ccc" ; blocksize = 5; eval(parse(evalInsert(cmdStr)));

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

Jan 12, 2017 6:45 AM
(2318 views)

One more approach using the eval(evalexpr( ... expr( x ) ... )) pattern

```
dt=newtable("example", newcolumn("col"));
blockSize = 15;
```**eval**(**evalexpr**(col<<set formula(Sequence(1,1000,1,**expr**(blockSize)))));

The problem all of these solutions are solving is pre-evaluating part of the expression, but not all of it.

EvalExpr() is a function that partially evaluates its argument. The parts that you want evaluated are inside Expr() functions. (Thus the name, EvalExpr.) The result is an expression, which needs to be evaluated to perform the setFormula operation.

Craige