<?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 How to extract items in a list from another list with partial matches to items in a third list? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-extract-items-in-a-list-from-another-list-with-partial/m-p/713323#M89669</link>
    <description>&lt;P&gt;I have the following lists&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;bigList  = {"CD_CORN_1", "ICS_CORN_6", "IPEK21_S00R_P37_2", "CURR_S009_P37_2", "CD_CORN_2", "Ig_RF", "Cmax03_4C230RF", "NG"};
smallList1  = {"CD_CORN_", "CD_CORN_", "CD_CORN_"}; //note these are repeats and that is how I get them
smallList2  = {"IDS_CORN_", "IPEK21_S00R_", "CURR_S009_"};
smallList3  = {"RF", "IPEK21_S00R_", "CURR_S009_", "NG"};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;using &lt;EM&gt;biglist&lt;/EM&gt; and &lt;EM&gt;smalllist1&lt;/EM&gt;, I want to get&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;sbigList1  = {"CD_CORN_1", "CD_CORN_2"};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;using &lt;EM&gt;biglist&lt;/EM&gt; and &lt;EM&gt;smalllist2&lt;/EM&gt;, I want to get&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;sbigList2  = {"ICS_CORN_6", "IPEK21_S00R_P37_2", "CURR_S009_P37_2"};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;using &lt;EM&gt;biglist&lt;/EM&gt; and &lt;EM&gt;smalllist3&lt;/EM&gt;, I want to get&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;sbigList3  = {"IPEK21_S00R_P37_2", "CURR_S009_P37_2", "Ig_RF", "Cmax03_4C230RF", "NG"};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How to do this via JSL?&lt;/P&gt;&lt;P&gt;(order of items in sbiglist's do not matter)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jan 2024 15:02:05 GMT</pubDate>
    <dc:creator>Neo</dc:creator>
    <dc:date>2024-01-03T15:02:05Z</dc:date>
    <item>
      <title>How to extract items in a list from another list with partial matches to items in a third list?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-extract-items-in-a-list-from-another-list-with-partial/m-p/713323#M89669</link>
      <description>&lt;P&gt;I have the following lists&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;bigList  = {"CD_CORN_1", "ICS_CORN_6", "IPEK21_S00R_P37_2", "CURR_S009_P37_2", "CD_CORN_2", "Ig_RF", "Cmax03_4C230RF", "NG"};
smallList1  = {"CD_CORN_", "CD_CORN_", "CD_CORN_"}; //note these are repeats and that is how I get them
smallList2  = {"IDS_CORN_", "IPEK21_S00R_", "CURR_S009_"};
smallList3  = {"RF", "IPEK21_S00R_", "CURR_S009_", "NG"};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;using &lt;EM&gt;biglist&lt;/EM&gt; and &lt;EM&gt;smalllist1&lt;/EM&gt;, I want to get&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;sbigList1  = {"CD_CORN_1", "CD_CORN_2"};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;using &lt;EM&gt;biglist&lt;/EM&gt; and &lt;EM&gt;smalllist2&lt;/EM&gt;, I want to get&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;sbigList2  = {"ICS_CORN_6", "IPEK21_S00R_P37_2", "CURR_S009_P37_2"};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;using &lt;EM&gt;biglist&lt;/EM&gt; and &lt;EM&gt;smalllist3&lt;/EM&gt;, I want to get&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;sbigList3  = {"IPEK21_S00R_P37_2", "CURR_S009_P37_2", "Ig_RF", "Cmax03_4C230RF", "NG"};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How to do this via JSL?&lt;/P&gt;&lt;P&gt;(order of items in sbiglist's do not matter)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 15:02:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-extract-items-in-a-list-from-another-list-with-partial/m-p/713323#M89669</guid>
      <dc:creator>Neo</dc:creator>
      <dc:date>2024-01-03T15:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract items in a list from another list with partial matches to items in a third list?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-extract-items-in-a-list-from-another-list-with-partial/m-p/713348#M89672</link>
      <description>&lt;P&gt;Here is how I would do it&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);
bigList  = {"CD_CORN_1", "ICS_CORN_6", "IPEK21_S00R_P37_2", "CURR_S009_P37_2", "CD_CORN_2", "Ig_RF", "Cmax03_4C230RF", "NG"};
smallList1  = {"CD_CORN_"}; //note these are repeats and that is how I get them
smallList2  = {"IDS_CORN_", "IPEK21_S00R_", "CURR_S009_"};
smallList3  = {"RF", "IPEK21_S00R_", "CURR_S009_", "NG"};

foundList = {};

For Each( {theList}, bigList,
	For Each( {sublist}, smallList1,
		if(contains(theList,sublist),
			insert into(foundlist, theList)
		)
	);
	For Each( {sublist}, smallList2,
		if(contains(theList,sublist),
			insert into(foundlist, theList)
		)
	);
	For Each( {sublist}, smallList3,
		if(contains(theList,sublist),
			insert into(foundlist, theList)
		)
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Each separate element of bigList has to be evaluated separately.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 15:10:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-extract-items-in-a-list-from-another-list-with-partial/m-p/713348#M89672</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-01-03T15:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract items in a list from another list with partial matches to items in a third list?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-extract-items-in-a-list-from-another-list-with-partial/m-p/713358#M89674</link>
      <description>&lt;P&gt;I would most likely create a function for something like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

bigList = {"CD_CORN_1", "ICS_CORN_6", "IPEK21_S00R_P37_2", "CURR_S009_P37_2", "CD_CORN_2", "Ig_RF", "Cmax03_4C230RF", "NG"};
smallList1 = {"CD_CORN_", "CD_CORN_", "CD_CORN_"};
smallList2 = {"IDS_CORN_", "IPEK21_S00R_", "CURR_S009_"};
smallList3 = {"RF", "IPEK21_S00R_", "CURR_S009_", "NG"};

get_partial_matches = function({to_list, with_list}, {Default Local},
	/*""" Get partial matches to_list using with_list
	
	Args:
		from_list (list(str)): list to compare to
		to_list (list(str)): list to compare with
	
	Returns:
		list(str): List with partial matches in alphabetical order
	"""*/
	
	matches = Associative Array(); // associative array to avoid duplicates
	
	For Each({to_item}, to_list,
		For Each({with_item}, with_list,
			If(Contains(to_item, with_item),
				Insert Into(matches, to_item);
			);
		);
	);
	
	return(matches &amp;lt;&amp;lt; get keys); // &amp;lt;&amp;lt; get keys to get result in a list
);

list1 = get_partial_matches(bigList, smallList1);
list2 = get_partial_matches(bigList, smallList2);
list3 = get_partial_matches(bigList, smallList3);

show(list1, list2, list3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;other option would be something like this, but I would much rather use the earlier one&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;get_partial_matches2 = function({to_list, with_list}, {Default Local},	
	
	matches = Associative Array(); 
	pattern = Concat Items(with_list, "|");
	
	For Each({to_item}, to_list,
		res = Regex(to_item, pattern);
		If(!IsMissing(res),
			Insert Into(matches, to_item);
		);
	);
	
	return(matches &amp;lt;&amp;lt; get keys);
);

list1 = get_partial_matches2(bigList, smallList1);
list2 = get_partial_matches2(bigList, smallList2);
list3 = get_partial_matches2(bigList, smallList3);

show(list1, list2, list3);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jan 2024 15:29:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-extract-items-in-a-list-from-another-list-with-partial/m-p/713358#M89674</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-01-03T15:29:02Z</dc:date>
    </item>
  </channel>
</rss>

