Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Re: How to filter a list based on another list

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

May 17, 2017 1:54 AM
(4745 views)

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

- ColList --> contain my table column names
- 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

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

```
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;
```

2 REPLIES 2

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

```
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;
```

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: How to filter a list based on another list

Ian

thank you,

the EndsWith function works perfectly ...

best regards

Lionel

thank you,

the EndsWith function works perfectly ...

best regards

Lionel

Article Labels

There are no labels assigned to this post.