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
- :
- Variables Not Defined in Formula in the 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
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Variables Not Defined in Formula in the script

Jun 25, 2019 4:42 PM
(600 views)

I am trying to create a new formula column using variables that were calculated earlier in the script, but the formula does not like the way the variables are defined. When I open the formula (after the data table is created) I see this error "This name exists in the current context but is not defined locally in the formula."

```
//Checks the calibration accuracy
current data table(dt_1C_comparison);
Avg_1C_grab = :"New Diff." << get values;
Avg_1C_diff = mean(Avg_1C_grab);
show(Avg_1C_diff);
offsetadjust_1Cpos = Avg_1C_diff - 0.3;
offsetadjust_1Cneg = Avg_1C_diff + 0.3;
x1C = If(
(Avg_1C_diff > 0.3), offsetadjust_1Cpos,
(Avg_1C_diff < -0.3), offsetadjust_1Cneg,
Avg_1C_diff = 0,
);
current data table(dt_1C_comparison);
//Caclulates new offset if the wet/dry difference is greater then 0.3
Offset_1C = Mean1C_intercept - x1C;
Show(Offset_1C);
New Column("Wet Avg. 2", numeric, "continuous", Format("Best", 5), Formula(:"Average of Meas. Position=TopDRY" * Slope_1C + Offset_1C));
```

Any help would be greatly appreciated!

2 REPLIES 2

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

Re: Variables Not Defined in Formula in the script

The issue is your construction of the formula. The way you are defining it, the formula will be stored exactly as you create it:

`:"Average of Meas. Position=TopDRY" * Slope_1C + Offset_1C`

When the formula runs, it is going to look for JSL variables called Slope_1C and Offset_1C. It is hard for me to imaging that if you save the data table, and then some time in the future, you start up a JMP session, and open this data table, that there will be JSL variables by those names currently available in your JMP session. So what you need to do, is to replace the variable references with the actual values of the JSL variables, something like:

`:"Average of Meas. Position=TopDRY" * .5 + 3.2`

I am just making up the values for Slope_1C and Offset_1C as being .5 and 3.2 respectively.

To do this, I find the easiest way to do this is to use the Substitute() function. Here is your script modified to substitute into your formula, the actual current values of the JSL variables.

```
//Checks the calibration accuracy
Current Data Table( dt_1C_comparison );
Avg_1C_grab = :"New Diff." << get values;
Avg_1C_diff = Mean( Avg_1C_grab );
Show( Avg_1C_diff );
offsetadjust_1Cpos = Avg_1C_diff - 0.3;
offsetadjust_1Cneg = Avg_1C_diff + 0.3;
x1C = If(
(Avg_1C_diff > 0.3), offsetadjust_1Cpos,
(Avg_1C_diff < -0.3), offsetadjust_1Cneg,
Avg_1C_diff = 0,
);
Current Data Table( dt_1C_comparison );
//Caclulates new offset if the wet/dry difference is greater then 0.3
Offset_1C = Mean1C_intercept - x1C;
Show( Offset_1C );
Eval(
Substitute(
Expr(
New Column( "Wet Avg. 2",
numeric,
"continuous",
Format( "Best", 5 ),
Formula( :Name("Average of Meas. Position=TopDRY") * __Slope_1C__ + __Offset_1C__ )
)
),
Expr( __Slope_1C__ ), Slope_1C,
Expr( __Offset_1C__ ), Offset_1C
)
);
```

Jim

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

Re: Variables Not Defined in Formula in the script

Thanks that worked!

There a couple points in my script where I calculate new columns based on variables calculated earlier in my script, similar to the method in my original post. Should I use be using thisEval( Substitute( for all the columns I calculate (if there are varibles in it)?