cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Choose Language Hide Translation Bar

Using variables in column formulas

CriticalMarten1_0-1697208584578.png

I want to change all references to "AGC EXP101P 2" to the variable 'colname' so that when I run the script this code applies to the selected column in the data table and not just the column "AGC EXP101P 2". However, when I try to change it, JMP always reads the variable name as a string in the column formula and doesn't evaluate properly. How do I fix this so that the column formula recognises the variable?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Using variables in column formulas

Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute is good post regarding this. << Get Selected Columns() does return a list of columns, so you might have to take that into account somehow (not sure why Column(cols) works, but I would suggest changing it to Column(cols[1])).

 

Edit:

Here is one example what you could do. If you have any questions, please ask!

Names Default To Here(1);

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

dt << Select Columns({"height", "weight"});

sel_cols = dt << get selected columns("String");


Eval(EvalExpr(
	dt << New Column("Mean " ||sel_cols[1], Numeric, Continuous, Formula(
		Mean(Expr(NameExpr(AsColumn(dt, sel_cols[1])))[1::20])
	));
));

 

jthi_0-1697211500658.png

 

-Jarmo

View solution in original post

1 REPLY 1
jthi
Super User

Re: Using variables in column formulas

Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute is good post regarding this. << Get Selected Columns() does return a list of columns, so you might have to take that into account somehow (not sure why Column(cols) works, but I would suggest changing it to Column(cols[1])).

 

Edit:

Here is one example what you could do. If you have any questions, please ask!

Names Default To Here(1);

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

dt << Select Columns({"height", "weight"});

sel_cols = dt << get selected columns("String");


Eval(EvalExpr(
	dt << New Column("Mean " ||sel_cols[1], Numeric, Continuous, Formula(
		Mean(Expr(NameExpr(AsColumn(dt, sel_cols[1])))[1::20])
	));
));

 

jthi_0-1697211500658.png

 

-Jarmo