cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
MuttonChops
Level III

Evaluating a variable column list as a string and inserting into a new column formula

I've created a variable that is a string of column names.  This is inside a FOR loop so it will change with each loop.

Here is a sample table for demonstration, in reality my table is about 400 columns with weird names.  I'm trying to group columns that should be grouped and report the max value. 99.9% of the time there will only be 1 value per row for each 'like' column that is to be grouped.

Col1Col2Col3
22  
 22 
  32
 32 
1  
  56
 34 

 

This first part is a loop that generates a variable column list.  I don't have all the code here but here is a summary.  This works so I don't want to bog down the discussion in this.

 

VarCols = functional code here and the output is a string with this format: {"col1", "col2", "col3"}

 

Then my code is supposed to create a new column named 'VarName' (defined in another part of the loop) then insert a formula that reports the max value of whichever columns are in VarCols.  But I just can't get it to evaluate.  Am I doing this way wrong?

 

DT << New Column(VarName, Numeric, "Continuous", formula(Maximum(columns(eval(VarCols)))));

Here is the specific error though i inserted the variable column name to avoid confusion:

Column VarName Formula Interrupted
Name Unresolved: columns 1 times At rows: 2 Operation: columns, columns( Eval( VarCols) ) /*###*/
Formula evaluation errors have been ignored

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Evaluating a variable column list as a string and inserting into a new column formula

Another community member may have a more efficient piece of code, but here is how I would code your request

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );
VarCols = {"NPN1", "PNP2", "NPN2"};

VarName = "NewCol";

// Create the JSL required to generate the new column
theExpr = "DT << New Column(VarName, Numeric, Continuous, formula(Maximum(:" || VarCols[1];
For( i = 2, i <= N Items( VarCols ), i++,
	theExpr = theExpr || ",:" || VarCols[i]
);
theExpr = theExpr || ")));";
// Run the generated JSL
Eval( Parse( theExpr ) );
Jim

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: Evaluating a variable column list as a string and inserting into a new column formula

Another community member may have a more efficient piece of code, but here is how I would code your request

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );
VarCols = {"NPN1", "PNP2", "NPN2"};

VarName = "NewCol";

// Create the JSL required to generate the new column
theExpr = "DT << New Column(VarName, Numeric, Continuous, formula(Maximum(:" || VarCols[1];
For( i = 2, i <= N Items( VarCols ), i++,
	theExpr = theExpr || ",:" || VarCols[i]
);
theExpr = theExpr || ")));";
// Run the generated JSL
Eval( Parse( theExpr ) );
Jim
MuttonChops
Level III

Re: Evaluating a variable column list as a string and inserting into a new column formula

That worked, thanks @txnelson 

SimFred
Level I

Re: Evaluating a variable column list as a string and inserting into a new column formula

Long time fan. First time I actually need to post to get a question answered.

 

This is great. I just managed to get to that same point in my code. The next step is to inser this string into a function in a new column. 

dt << New Column( "MinValue", numeric, continuous, Formula( min(Eval( Parse( TheExpr)))));

but that is not working for me. Any help would be appreciated.

 

Please ignore. Brain was not working right late tonight...

txnelson
Super User

Re: Evaluating a variable column list as a string and inserting into a new column formula

Please provide the value of "TheExpr"

Jim