- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
How can I combine text strings that are in a different order?
Hard to explain in words, but the attached file should clarify my problem. I have data for a number of airplane tickets with originating (column ORIGIN) and terminating (column DEST) airports. I also combined these to show the route. But I want the route from A to B to be the same as the route from B to A. Right now, this will appear as two different strings, for example ANC to ADK is distinct from ADK to ANC. I would like a column to identify these as the same route and not two distinct routes. I haven't yet figured out a way to do this.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How can I combine text strings that are in a different order?
Hi Dale, just create a new column and enter the code as formula:
alternatively, open a script window and run this code:
New Column( "Concatenate[ORIGIN,DEST]", Character,
Formula( Concat Items( Sort List( Eval List( {:ORIGIN, :DEST} ) ), "-" ) ))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How can I combine text strings that are in a different order?
You could create a list of your values in a single row, sort that and finally concatenate the values in sorted list together.
Below is one option using associative array
Concat Items(Associative Array(Eval List({:ORIGIN, :DEST})) << Get Keys, "-")
but using something like this should also work nicely
Concat Items(Sort List(Eval List({:ORIGIN, :DEST})), "-")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How can I combine text strings that are in a different order?
I'm an experienced JMP user, but I have avoided scripting. I can't figure out how to use your solution. When I enter that script (with ; and the end), nothing happens. What am I missing?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How can I combine text strings that are in a different order?
Hi Dale, just create a new column and enter the code as formula:
alternatively, open a script window and run this code:
New Column( "Concatenate[ORIGIN,DEST]", Character,
Formula( Concat Items( Sort List( Eval List( {:ORIGIN, :DEST} ) ), "-" ) ))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How can I combine text strings that are in a different order?
Thanks to both hogi and jthi. You are both spoiling me, as there is little reason for me to learn JSL when you solve my problems for me. But don't worry - I'm old enough that I'm not learning bad habits, and I urge my students to learn scripting even if I don't see the sense of it for me. But it does illustrate something I've been thinking about after 45 years of teaching: the real valuable skill is being able to ask questions, not answer them. There are plenty of answers available, but you need to ask a good question to get good answers (especially true in this era of AI and LLMs).