One of the great things about attending the JMP Discovery Summit as a developer is hearing questions and suggestions from people with so many different applications of JMP. One JMP Scripting Language (JSL) question came up three times, so it's worth sharing. The question is, "How do I remove duplicate items from a list?"

That is, given the list** {"like", "dislike", "like", "neutral", "dislike", "like"}** the result should be **{"dislike", "like", "neutral"}** (order not important).

There are probably lots of reasonable ways to do that in JSL (other ideas are welcome), but the simplest I could think of is to use an *associative array*. An associative array is a collection of key-value pairs where the keys are unique. If you add more than one key-value pair with the same key, only one of them is kept (the last one). If you don't care about the values, then the associative array is effectively a set of unique keys.

In JSL, you can create an associative array in several ways, but the only one of interest here is to create it from a list. The resulting associative array will treat the list values as keys and only store the unique keys. Then we can ask the associative array for a list of its keys.

answers = **{**"like", "dislike", "like", "neutral", "dislike", "like"**}**;

answers set = Associative Array**(** answers **)**;

unique answers = answers set << Get Keys;

**Result: {"dislike", "like", "neutral"}**

If you haven't discovered associative arrays in JMP, explore the docs and the examples in the JSL Scripting Index.

Now, it's your turn: What other ways can you get unique values from a list? I can think of one using the Summarize() function...

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.