cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
dlehman1
Level V

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.

1 ACCEPTED SOLUTION

Accepted Solutions
hogi
Level XII

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:

hogi_0-1708182142242.png

 

alternatively, open a script window and run this code:

New Column( "Concatenate[ORIGIN,DEST]",	Character,
	Formula( Concat Items( Sort List( Eval List( {:ORIGIN, :DEST} ) ), "-" ) ))

View solution in original post

4 REPLIES 4
jthi
Super User

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})), "-")
-Jarmo
dlehman1
Level V

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?

hogi
Level XII

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:

hogi_0-1708182142242.png

 

alternatively, open a script window and run this code:

New Column( "Concatenate[ORIGIN,DEST]",	Character,
	Formula( Concat Items( Sort List( Eval List( {:ORIGIN, :DEST} ) ), "-" ) ))
dlehman1
Level V

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).