BookmarkSubscribe
Choose Language Hide Translation Bar
xdcurryx
Community Trekker

Variables Not Defined in Formula in the script

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!

0 Kudos
2 REPLIES 2
txnelson
Super User

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
xdcurryx
Community Trekker

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)?

0 Kudos