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
yanee
Level III

loop and concatenate

I need to create a new column which is a concatenate of a set of column 

I just hard code the column name as below ...

 

new column("Code","character",
formula(:deliver || :func_groupa || :func_groupb_h || :func_groupb_l || :micro firmware load
|| :micro module build || :micro setup)
);

 

however, I want to create a script that can get the number of column from that input file and start concatenate the value inside (same as above) 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: loop and concatenate

Here is one way to do what you want

names default to here( 1 );
// Open a sample data table
dt = Open( "$SAMPLE_DATA/big class.jmp" );

// Get all of the character columns for concatenating
colNames = dt << get column names(character,string);

// Build a command string that generates the JSL to create the column
theExpr = "dt << new column( \!"concat\!", character, formula( concat(:" || colNames[1];

For( i = 2, i <= N Items( colNames ), i++,
	theExpr = theExpr || ",:" || colNames[i]
);

theExpr = theExpr || ")));";

// Run the command string
Eval( Parse( theExpr ) );
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: loop and concatenate

Here is one way to do what you want

names default to here( 1 );
// Open a sample data table
dt = Open( "$SAMPLE_DATA/big class.jmp" );

// Get all of the character columns for concatenating
colNames = dt << get column names(character,string);

// Build a command string that generates the JSL to create the column
theExpr = "dt << new column( \!"concat\!", character, formula( concat(:" || colNames[1];

For( i = 2, i <= N Items( colNames ), i++,
	theExpr = theExpr || ",:" || colNames[i]
);

theExpr = theExpr || ")));";

// Run the command string
Eval( Parse( theExpr ) );
Jim
yanee
Level III

Re: loop and concatenate

Thank you so much ..