<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to use contains within match? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/256976#M50485</link>
    <description>&lt;P&gt;There is no case statement or function in JSL. You must use the If() function or the Match() function. The arguments must be exhaustive - include all known cases. Here is a short example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 );

food item = List( "apple", "banana", "ham", "chicken" );

kind of food = List();

For( i = 1, i &amp;lt;= N Items( food item), i++,
	Insert Into( kind of food,
		Match( food item[i],
			"apple", "fruit",
			"banana", "fruit",
			"ham", "meat",
			"chicken", "meat",
			"unknown"
		);
	);
);

Show( kind of food );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I do not see how the Contains() function applies based on your brief description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might also use an associative array with [ item =&amp;gt; kind ] pairs for look up.&lt;/P&gt;</description>
    <pubDate>Thu, 09 Apr 2020 12:45:24 GMT</pubDate>
    <dc:creator>Mark_Bailey</dc:creator>
    <dc:date>2020-04-09T12:45:24Z</dc:date>
    <item>
      <title>how to use contains within match?</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/256919#M50474</link>
      <description>&lt;P&gt;I have some text in a listA.I want to create another listB based on the value in listA.If the listA text contains apple then list B should be fruit;if list A has tomato listB should be vegetable;if listA has daisy listB should be flower.If none of these match then listB should have unknown.Also search needs to be case insensitive.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looking for something equivalent to case statement in JMP.I'm exploring match() function but having a little trouble using contains inside match.&lt;/P&gt;&lt;P&gt;any help appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 00:05:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/256919#M50474</guid>
      <dc:creator>ENTHU</dc:creator>
      <dc:date>2020-04-09T00:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to use contains within match?</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/256976#M50485</link>
      <description>&lt;P&gt;There is no case statement or function in JSL. You must use the If() function or the Match() function. The arguments must be exhaustive - include all known cases. Here is a short example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 );

food item = List( "apple", "banana", "ham", "chicken" );

kind of food = List();

For( i = 1, i &amp;lt;= N Items( food item), i++,
	Insert Into( kind of food,
		Match( food item[i],
			"apple", "fruit",
			"banana", "fruit",
			"ham", "meat",
			"chicken", "meat",
			"unknown"
		);
	);
);

Show( kind of food );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I do not see how the Contains() function applies based on your brief description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might also use an associative array with [ item =&amp;gt; kind ] pairs for look up.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2020 12:45:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/256976#M50485</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2020-04-09T12:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to use contains within match?</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/256990#M50488</link>
      <description>&lt;P&gt;Here's a way to do it using an associative array.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Create an associative array for the different types of food
food_aa = associative array();
food_aa["Fruit"]  = {"apple", "pear", "banana", "plum"};
food_aa["Meat"]   = {"ham", "chicken", "beef", "fish"};
food_aa["Flower"] = {"daisy", "sunflower", "aster", "peony"};

// List of foods to match up
food_item = List( "apple", "banana", "ham", "chicken", "daisy" );

kind_of_food = {};

For( i = 1, i &amp;lt;= N Items( food_item), i++,

	if (contains(food_aa["Fruit"], food_item[i]),
		insert into (kind_of_food, "fruit");
		,
		contains(food_aa["Meat"], food_item[i]),
		insert into (kind_of_food, "meat");
		,
		contains(food_aa["Flower"], food_item[i]),
		insert into (kind_of_food, "flower");
	);
);

Show( kind_of_food );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Apr 2020 12:57:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/256990#M50488</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2020-04-09T12:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to use contains within match?</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/258576#M50787</link>
      <description>&lt;P&gt;I am wanting to use contains statement because the food item list might have words like "applesauce" or "hamburger".If the list contains "applesauce" then I want to tag this a fruit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 20:40:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/258576#M50787</guid>
      <dc:creator>ENTHU</dc:creator>
      <dc:date>2020-04-16T20:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to use contains within match?</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/258577#M50788</link>
      <description>&lt;P&gt;May be i dint explain the problem well.My listA contains a big string of which apple or ham may be a part.If the string in listA contains apple then I want to write string called "fruit" in listB.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 20:45:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/258577#M50788</guid>
      <dc:creator>ENTHU</dc:creator>
      <dc:date>2020-04-16T20:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to use contains within match?</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/258587#M50790</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Here is a very basic script that looks into a list called listA, and if it finds the string apple, it places into a list called listB, the word Fruit.
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);
listA = {"Pear", "applesauce", "ham"};
listB = {};
If( contains(uppercase(char(listA)), uppercase("apple")), insert into(listB, "Fruit"));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: inherit; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 1.7142; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;I don't think that this is what you want.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;When you say "list" are you talking about a JMP list, or what?&lt;/LI&gt;
&lt;LI&gt;When you say place it into listB, is that a JMP list, or are you just talking about a long string.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Thu, 16 Apr 2020 22:57:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/258587#M50790</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-04-16T22:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to use contains within match?</title>
      <link>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/258645#M50803</link>
      <description>&lt;P&gt;Try this script.&amp;nbsp; Uses associative arrays as before, but this time does a contains search&amp;nbsp; for a string within a string.&amp;nbsp; So contains("applesauce", "apple") will find a match.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Create an associative array for the different types of food
food_aa = associative array();
food_aa["Fruit"]  = {"apple", "pear", "banana", "plum"};
food_aa["Meat"]   = {"ham", "chicken", "beef", "fish"};
food_aa["Flower"] = {"daisy", "sunflower", "aster", "peony"};

// List of foods to match up
food_items = List( "applesauce", "banana split", "hambone", "chicken", "daisyflower", "corvette" );

kind_of_food = {};

keylist = food_aa &amp;lt;&amp;lt; get keys();

For( i = 1, i &amp;lt;= N Items( food_items), i++,
	one_food = food_items[i];
	for (k = 1, k &amp;lt;= nitems(keylist), k++,
		one_key = keylist[k];
		food_type_list = food_aa[one_key];
		found_match = 0;
		for (m = 1, m &amp;lt;= nitems(food_type_list), m++,
			one_type_food = food_type_list[m];
			if (contains(one_food, one_type_food),
				insert into (kind_of_food, one_key);
				print("Found match: " || one_key);
				found_match = 1;
				break();	// found a match - no need to keep looking at other foods
			);
		);
		if (found_match, break());	// found a match - no need to keep looking for a food type
	);
	if (!found_match,
		print("No match found for " || one_food)
	);
);

Show( kind_of_food );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here are the results from the log:&lt;/P&gt;
&lt;PRE&gt;"Found match: Fruit"
"Found match: Fruit"
"Found match: Meat"
"Found match: Meat"
"Found match: Flower"
"No match found for corvette"
kind_of_food = {"Fruit", "Fruit", "Meat", "Meat", "Flower"};&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Apr 2020 12:43:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/how-to-use-contains-within-match/m-p/258645#M50803</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2020-04-17T12:43:26Z</dc:date>
    </item>
  </channel>
</rss>

