cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
KinKame
Level IV

How to filter a list based on another list

Hello 

it should be easy but I cannot figure out by myself.

I have 2 lists and I would like to filter the first 1 based on the second 

  1. ColList --> contain my table column names 
  2. CompList --> contain extractant

For example 

ColList = ("aa_Lio", "aa_Leo", "ab_Lio", "ab_Leo", "ac_Lio", "ac_Leo", "ad_Lio", "ad_Leo" )

CompList = ("Lio")

Goal

create a list which I call extractCol whichwould be in my example extractCol = ("aa_Lio", "ab_Lio", "ac_Lio", "ad_Lio")

 

here is my script. If i dont use the For loop it works ...

For( k = 1, k <= 1, k++,
  For( i = 1, i <= 3, i++,
    If( Contains( ColList[i], CompList[k]) >=1 ,
       Insert Into( extractCol, ColList[i] )
    )
  );
);

 

Best regards

Lionel

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Level X

Re: How to filter a list based on another list

NamesDefaultToHere(1);

ColList = {"aa_Lio", "aa_Leo", "ab_Lio", "ab_Leo", "ac_Lio", "ac_Leo", "ad_Lio", "ad_Leo" };
CompList = {"Lio"};

extractCol = {};
for(k=1, k<=NItems(CompList), k++,
	for(i=1, i<=NItems(ColList), i++,
		if(EndsWith(ColList[i], CompList[k]), InsertInto(extractCol, colList[i]));
	);
);
extractCol;

View solution in original post

2 REPLIES 2
ian_jmp
Level X

Re: How to filter a list based on another list

NamesDefaultToHere(1);

ColList = {"aa_Lio", "aa_Leo", "ab_Lio", "ab_Leo", "ac_Lio", "ac_Leo", "ad_Lio", "ad_Leo" };
CompList = {"Lio"};

extractCol = {};
for(k=1, k<=NItems(CompList), k++,
	for(i=1, i<=NItems(ColList), i++,
		if(EndsWith(ColList[i], CompList[k]), InsertInto(extractCol, colList[i]));
	);
);
extractCol;
KinKame
Level IV

Re: How to filter a list based on another list

Ian
thank you,
the EndsWith function works perfectly ...
best regards
Lionel

Recommended Articles