cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
jsolo01
Level II

concatenating cells

I am trying to convert rows grouped by a composite variable into a concatenated cell sepearated by a space based on the grouping variable.  Example:

Screenshot 2026-04-24 at 8.20.36 AM.png

into:
 
Screenshot 2026-04-24 at 8.21.25 AM.png

 \

 
The code below creates a grouping column and a "N rows" column but i cant get the contents of the cells concatenated.
 
dt = Current Data Table();

dt_summary = dt << Summary(
Group( :Column B ),
Statistics(
Concatenate( :Column A, " " )
)
);
 
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
mmarchandFSLR
Level VI

Re: concatenating cells

You could do it this way.  This accounts for the possibility of duplicates in Column A and only lists each item once.

 

Names Default To Here( 1 );
dt = Current Data Table();
Summarize( dt, cats = By( :Column B ) );
dt_summary = New Table( "Summary", New Column( "Category", Character, "Nominal" ), New Column( "Items", Character, "Nominal" ) );
For Each( {v, i}, cats,
	dt_summary << Add Rows(
		{:Category = v, :Items = Concat Items( Associative Array( dt:Column A[Where( dt, :Column B == v )] ) << Get Keys, " " )}
	)
);

View solution in original post

4 REPLIES 4
mmarchandFSLR
Level VI

Re: concatenating cells

You could do it this way.  This accounts for the possibility of duplicates in Column A and only lists each item once.

 

Names Default To Here( 1 );
dt = Current Data Table();
Summarize( dt, cats = By( :Column B ) );
dt_summary = New Table( "Summary", New Column( "Category", Character, "Nominal" ), New Column( "Items", Character, "Nominal" ) );
For Each( {v, i}, cats,
	dt_summary << Add Rows(
		{:Category = v, :Items = Concat Items( Associative Array( dt:Column A[Where( dt, :Column B == v )] ) << Get Keys, " " )}
	)
);
jthi
Super User

Re: concatenating cells

I like doing this with SQL Query from JMP table

Names Default To Here(1); 

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

dt_concat = Query(
	Table(dt, "t1"),
	"\[
SELECT age, GROUP_CONCAT(sex) as g,
count(*) as n
FROM t1
GROUP BY age
	]\"
);

You can also ignore duplicates by adding DISTINCT to the group concat

Names Default To Here(1); 

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

dt_concat = Query(
	Table(dt, "t1"),
	"\[
SELECT age, GROUP_CONCAT(DISTINCT sex) as g,
count(*) as n
FROM t1
GROUP BY age
	]\"
);

jthi_0-1777046442491.png

 

-Jarmo
jsolo01
Level II

Re: concatenating cells

thanks for the reply.  havent done a SQL query but will give it a try.

jthi
Super User

Re: concatenating cells

There is also a wish list item Add Listagg/Concatenate/GROUP_CONCAT to Summary platform 

-Jarmo

Recommended Articles