<?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: Remove element from a list that contain elements from a second list in JSL in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803782#M98119</link>
    <description>&lt;P&gt;Hello Jarmo,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks the Filter each () seems to do the trick, even with more intricate inputs (see below).&lt;/P&gt;&lt;P&gt;Ideally I need the options to filter ChosenDataCol with the 2 ways:&lt;/P&gt;&lt;P&gt;- Remove unwanted elements based on list of string (this method here, which works now) =&amp;gt; RemoveCol&lt;/P&gt;&lt;P&gt;- Only keep elements based on list of string (the opposite of the method here)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought removing the "NOT" from "!Contains()" should do the trick but it returns an empty list { }.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know why?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Remove elements &amp;lt;-- works well&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

ChosenDataCol = {"SiCal 1", "Ba Cal 2", "toCal 3", "Si Temp1", "bouTemp25", "CaBlue 56", "SiBlue 32", "Blue 95"};
RemoveCol = {"Cal", "Blue"};

vals = Filter Each({val1}, ChosenDataCol,
	res = Filter Each({val2}, RemoveCol,
		!Contains(val1, val2)
	);
	N Items(res) == N Items(RemoveCol);
);

// log : {"Si Temp1", "bouTemp25"}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Keep elements &amp;lt;-- doesn't work&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

ChosenDataCol = {"SiCal 1", "Ba Cal 2", "toCal 3", "Si Temp1", "bouTemp25", "CaBlue 56", "SiBlue 32", "Blue 95"};
KeepCol = {"Cal", "Blue"};

vals = Filter Each({val1}, ChosenDataCol,
	res = Filter Each({val2}, KeepCol,
		Contains(val1, val2)
	);
	N Items(res) == N Items(KeepCol);
);

// log : {}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 06 Oct 2024 17:25:04 GMT</pubDate>
    <dc:creator>Voizingu</dc:creator>
    <dc:date>2024-10-06T17:25:04Z</dc:date>
    <item>
      <title>Remove element from a list that contain elements from a second list in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803719#M98088</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Removing elements from a list is well documented in the the JSL discussions but for some reason I cannot figure out how to do this:&lt;/P&gt;&lt;P&gt;I need to remove elements from a list if the elements CONTAIN string from another list (not exact match).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example below: I am trying to remove all elements that contain "Cal" or "Blue"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Voiz&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
clear symbols();
Deletesymbols();

ChosenDataCol = {"Cal1", "Cal2", "Cal3", "Temp1", "Temp25", "Blue56", "Blue32", "Blue95"};

RemoveCol = {"Cal", "Blue"};

For (i=1,i&amp;lt;=N Items( RemoveCol ), i++,
	For (j=N Items (ChosenDataCol), j&amp;lt;=1, j--,
		If(contains(ChosenDataCol[j], Eval(RemoveCol[i]))==1, 
			Remove from(ChosenDataCol, j)
		)
	)
);

show (ChosenDataCol);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2024 23:15:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803719#M98088</guid>
      <dc:creator>Voizingu</dc:creator>
      <dc:date>2024-10-05T23:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Remove element from a list that contain elements from a second list in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803729#M98089</link>
      <description>&lt;P&gt;In your For() loop,&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;j&amp;lt;=1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;j&amp;gt;=1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
clear symbols();
Deletesymbols();

ChosenDataCol = {"Cal1", "Cal2", "Cal3", "Temp1", "Temp25", "Blue56", "Blue32", "Blue95"};

RemoveCol = {"Cal", "Blue"};

For (i=1,i&amp;lt;=N Items( RemoveCol ), i++,
	For (j=N Items (ChosenDataCol), j&amp;gt;=1, j--,
		If(contains(ChosenDataCol[j], RemoveCol[i])==1, 
			Remove from(ChosenDataCol, j)
		)
	)
);
show (ChosenDataCol);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Oct 2024 23:42:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803729#M98089</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-10-05T23:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: Remove element from a list that contain elements from a second list in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803730#M98090</link>
      <description>&lt;P&gt;Hi Jim,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ha yes, I missed that :)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;The solution works BUT it seems that the contains() is not very robust: if the String to look is in the middle of the list element, it doesn't find it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know why?&lt;/P&gt;&lt;P&gt;The log of the script below gives:&lt;/P&gt;&lt;PRE&gt;ChosenDataCol = {"Si Cal 1", "Ba Cal 2", "toCal 3", "Temp 1", "Temp 25", "SiBlue 32"};&lt;/PRE&gt;&lt;P&gt;instead of&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ChosenDataCol = {"Temp 1", "Temp 25"};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
clear symbols();
Deletesymbols();

ChosenDataCol = {"Si Cal 1", "Ba Cal 2", "toCal 3", "Temp 1", "Temp 25", "Blue 56", "SiBlue 32", "Blue 95"};

RemoveCol = {"Cal", "Blue"};

For (i=1,i&amp;lt;=N Items( RemoveCol ), i++,
	For (j=N Items (ChosenDataCol), j&amp;gt;=1, j--,
		If(contains(ChosenDataCol[j], Eval(RemoveCol[i]))==1, 
			Remove from(ChosenDataCol, j)
		)
	)
);

show (ChosenDataCol);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2024 02:28:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803730#M98090</guid>
      <dc:creator>Voizingu</dc:creator>
      <dc:date>2024-10-06T02:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Remove element from a list that contain elements from a second list in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803731#M98091</link>
      <description>&lt;P&gt;Please refer to my initial response JSL.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Contains( ChosenDataCol[j], Eval( RemoveCol[i] ) ) == 1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;was changed to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;contains(ChosenDataCol[j], RemoveCol[i])==1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which allows for the correct answer.&amp;nbsp; I am not sure why the Eval() is interfering with the Contains()&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2024 02:39:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803731#M98091</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-10-06T02:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Remove element from a list that contain elements from a second list in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803739#M98096</link>
      <description>&lt;P&gt;You can also utilize For Each or Filter Each&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

ChosenDataCol = {"Cal1", "Cal2", "Cal3", "Temp1", "Temp25", "Blue56", "Blue32", "Blue95"};
RemoveCol = {"Cal", "Blue"};

vals = Filter Each({val1}, ChosenDataCol,
	res = Filter Each({val2}, RemoveCol,
		!Contains(val1, val2)
	);
	N Items(res) == N Items(RemoveCol);
);

// ChosenDataCol = vals; // {"Temp1", "Temp25"}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Oct 2024 13:25:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803739#M98096</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-10-06T13:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Remove element from a list that contain elements from a second list in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803782#M98119</link>
      <description>&lt;P&gt;Hello Jarmo,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks the Filter each () seems to do the trick, even with more intricate inputs (see below).&lt;/P&gt;&lt;P&gt;Ideally I need the options to filter ChosenDataCol with the 2 ways:&lt;/P&gt;&lt;P&gt;- Remove unwanted elements based on list of string (this method here, which works now) =&amp;gt; RemoveCol&lt;/P&gt;&lt;P&gt;- Only keep elements based on list of string (the opposite of the method here)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought removing the "NOT" from "!Contains()" should do the trick but it returns an empty list { }.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know why?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Remove elements &amp;lt;-- works well&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

ChosenDataCol = {"SiCal 1", "Ba Cal 2", "toCal 3", "Si Temp1", "bouTemp25", "CaBlue 56", "SiBlue 32", "Blue 95"};
RemoveCol = {"Cal", "Blue"};

vals = Filter Each({val1}, ChosenDataCol,
	res = Filter Each({val2}, RemoveCol,
		!Contains(val1, val2)
	);
	N Items(res) == N Items(RemoveCol);
);

// log : {"Si Temp1", "bouTemp25"}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Keep elements &amp;lt;-- doesn't work&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

ChosenDataCol = {"SiCal 1", "Ba Cal 2", "toCal 3", "Si Temp1", "bouTemp25", "CaBlue 56", "SiBlue 32", "Blue 95"};
KeepCol = {"Cal", "Blue"};

vals = Filter Each({val1}, ChosenDataCol,
	res = Filter Each({val2}, KeepCol,
		Contains(val1, val2)
	);
	N Items(res) == N Items(KeepCol);
);

// log : {}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2024 17:25:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803782#M98119</guid>
      <dc:creator>Voizingu</dc:creator>
      <dc:date>2024-10-06T17:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: Remove element from a list that contain elements from a second list in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803784#M98121</link>
      <description>&lt;P&gt;You will also have to consider what N Items(res) == N Items(KeepCol); is doing. You can add extra print inside the loop to assist in figuring that out&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

ChosenDataCol = {"SiCal 1", "Ba Cal 2", "toCal 3", "Si Temp1", "bouTemp25", "CaBlue 56", "SiBlue 32", "Blue 95"};
KeepCol = {"Cal", "Blue"};

vals = Filter Each({val1}, ChosenDataCol,
	res = Filter Each({val2}, KeepCol,
		Contains(val1, val2)
	);
	show(res);
	N Items(res) != N Items(KeepCol);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also if you can have situations where both Cal and Blue can appear in single string, you will need to utilize a bit different method&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2024 17:36:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803784#M98121</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-10-06T17:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Remove element from a list that contain elements from a second list in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803785#M98122</link>
      <description>&lt;P&gt;Hello Jarmo,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The "&lt;SPAN&gt;show&lt;/SPAN&gt;(res)" helped me understand the logic. I really have to use For Each () functions more :)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;there was a missing "!" before Contains to make the script really work, but now my 2 functions work properly.&lt;/P&gt;&lt;P&gt;I will have to think about your last remark, not sure if that scenario exists!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Voiz&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);

ChosenDataCol = {"SiCal 1", "Ba Cal 2", "toCal 3", "Si Temp1", "bouTemp25", "CaBlue 56", "SiBlue 32", "Blue 95"};
KeepCol = {"Cal", "Blue"};

vals = Filter Each({val1}, ChosenDataCol,
	res = Filter Each({val2}, KeepCol,
		!Contains(val1, val2)
	);
	N Items(res) != N Items(KeepCol);
);

show(vals)

// vals = {"SiCal 1", "Ba Cal 2", "toCal 3", "CaBlue 56", "SiBlue 32", "Blue 95"};&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Oct 2024 18:09:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Remove-element-from-a-list-that-contain-elements-from-a-second/m-p/803785#M98122</guid>
      <dc:creator>Voizingu</dc:creator>
      <dc:date>2024-10-06T18:09:49Z</dc:date>
    </item>
  </channel>
</rss>

