cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

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

Concatenate columns with empty cells

Hi all,

I have a dataset with different columns that have some empty random cells (like the example in the table below). I would like to concatenate the values of the different columns and use the "_" to separate the content of the cells only if the content of the cells is different from empty value (as in column "concat" below). Does anyone have a suggestion on a how to to this operation in a smart way?

Thanks for your help! 

 

NameAgeSexConcat

Mads

31 Mads_31
  MM
John25 John_25
Julia19FJulia_19_F
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Concatenate columns with empty cells

Here is one way of writing the formula

colList = {"Column 1", "Column 2", "Column 3"};
x = "";
For( i = 1, i <= N Items( colList ), i++,
	If( As Column( colList[i] ) != "",
		If( x != "", x = x || "_" );
		x = x || Char( As Column( colList[i] ) );
	)
);
Trim( x );
Jim

View solution in original post

3 REPLIES 3

Re: Concatenate columns with empty cells

You should be able to use a simple function in a new column Concat:

 

formula.PNG

txnelson
Super User

Re: Concatenate columns with empty cells

Here is one way of writing the formula

colList = {"Column 1", "Column 2", "Column 3"};
x = "";
For( i = 1, i <= N Items( colList ), i++,
	If( As Column( colList[i] ) != "",
		If( x != "", x = x || "_" );
		x = x || Char( As Column( colList[i] ) );
	)
);
Trim( x );
Jim

Re: Concatenate columns with empty cells

Hi, here is yet another formula.

Concat Items( Words( :Name || "," || :Age || "," || :Sex, "," ), "_" )

Cheers,

Brady

Recommended Articles