- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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!
Name | Age | Sex | Concat |
Mads | 31 | Mads_31 | |
M | M | ||
John | 25 | John_25 | |
Julia | 19 | F | Julia_19_F |
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Concatenate columns with empty cells
You should be able to use a simple function in a new column Concat:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Concatenate columns with empty cells
Created:
Jun 3, 2021 12:02 PM
| Last Modified: Jun 3, 2021 9:15 AM
(1604 views)
| Posted in reply to message from JMP_fan 06-02-2021
Hi, here is yet another formula.
Concat Items( Words( :Name || "," || :Age || "," || :Sex, "," ), "_" )
Cheers,
Brady