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
ladomiqo
Level I

Concatenate values in a column

Seems like this should be simple, but I cannot find a clear example. I would like to concatinate the values in columns of a specific name("ROW" and "COL") and create a new column with the result in it. Example below.

 

ROW COL CELL

5 1 5_1

3 2 3_2

12 -1 12_-1

 

best shot at code so far:

 

column("ROW") << Data type(Character);
column("COL") << Data type(Character);

//a = {column("ROW"), column("COL")};  
ConExpr = concat items({column("ROW"), column("COL")} , "_"); 

//Add "CELL" column = concat col(ROW) "_" col(COL)
dt << new column("CELL",Character, "Nominal", Format("Best", 12), formula(eval(Expr(ConExpr))));

my results:

CELL

_

_

 

Any help in understanding why my code evaluates to that and the correct implementation would be greatly appreciated.

 

 

 

awesome sex cam sites: sex cams , free live sex cams, free cams
5 REPLIES 5
mlo1
Level IV

Re: Concatenate values in a column

I concatenated it the following way. Is this your Goal? Does it help?

 

mlo1_0-1645701183435.png

 

Georg
Level VII

Re: Concatenate values in a column

There are several issues in your script,

e.g. you need to put expressions in an "expr()" etc., please see scripting index for further documentation,

and try out.

 

BR

 

Names Default To Here( 1 );

dt = New Table( "Concatenate",
	Add Rows( 3 ),
	New Column( "ROW", Character, "Nominal", Set Values( {"5", "3", "12"} ) ),
	New Column( "COL", Character, "Nominal", Set Values( {"1", "2", "-1"} ) )
);
  
// ConExpr = expr(Concat Items( {Column( "ROW" )[Row()], Column( "COL" )[Row()]}, "_" )); 
ConExpr = expr(Concat Items( {:ROW, :COL}, "_" ); );

//Add "CELL" column = concat col(ROW) "_" col(COL)
dt << New Column( "CELL", Character, "Nominal", formula( Name Expr( ConExpr ) ) );
Georg
txnelson
Super User

Re: Concatenate values in a column

The New Column syntax can be simplified.  

Names Default To Here( 1 );

dt = New Table( "Concatenate",
	Add Rows( 3 ),
	New Column( "ROW", Character, "Nominal", Set Values( {"5", "3", "12"} ) ),
	New Column( "COL", Character, "Nominal", Set Values( {"1", "2", "-1"} ) )
);

// Creae new column
dt << New Column( "CELL1", Character,formula(:ROW || "_" || :COL) );
//or
dt << New Column( "CELL2", Character,formula( Concat( :ROW, "_", :COL) ) );
Jim
pmroz
Super User

Re: Concatenate values in a column

Jim's solution is the easiest - no need to overcomplicate things with expr, eval etc.  

Georg
Level VII

Re: Concatenate values in a column

sure, simply wanted to stay near to the given example. Eventually there is a more complex environment, that for expr was needed.

Georg