cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • We’re improving the Learn JMP page, and want your feedback! Take the survey
Choose Language Hide Translation Bar
MeanChris
Level I

Convert script variable to static value in New Column formula

Hello, I was writing some JSL to process a source file, and hoping to reuse/adapt the source file.  To that end I created a few very simple variables that I intended to change only occasionally.

 

Here is a short section of JSL that creates variables and uses them in a column formula.  These are not the original names.  I changed to keep it simple:

 

JMP v18.2.0

 

dt = current data table();

VariableA = 42; // A value I intend to change occasionally depending on the details of the source data

VariableB = 1; // Another value I'll change depending on the source data.

    dt << New Column( "A_New_Formula_Coumn",
    numeric,
    ordinal,
    Formula( :An_Existing_Data_Column - VariableA * VariableB )
    );

   dt << New Column( "A_Simpler_New_Formula_Coumn",
    numeric,
    ordinal,
    Formula( :An_Existing_Data_Column - 42 )
    );
I've run this in an external script and from a script in the table.  Both seem to have no trouble when the script is first run.  The problem is that "VariableA" and "VariableB" are used in the column formula, almost as if they are local variables.  But they aren't defined anywhere.  So when I close JMP down completely and reopen it - only then do I get a warning that there is something wrong with the formula:
MeanChris_0-1747947050994.png

 

 

I really just want the script to apply THIS formula to the new column, i.e. evaluate the script variable portion.  But I don't know how to do that.

MeanChris_1-1747947120991.png

I'd prefer NOT to use table variables.

 

Thanks for reading!

 
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Convert script variable to static value in New Column formula

You will have to evaluate them Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute

Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");

myvar = 100;

Eval(EvalExpr(
	dt << new column("A", Numeric, Continuous, Formula(
		:height * Expr(myvar)
	));
));

 

-Jarmo

View solution in original post

1 REPLY 1
jthi
Super User

Re: Convert script variable to static value in New Column formula

You will have to evaluate them Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute

Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");

myvar = 100;

Eval(EvalExpr(
	dt << new column("A", Numeric, Continuous, Formula(
		:height * Expr(myvar)
	));
));

 

-Jarmo

Recommended Articles