<?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 'like' or 'contains' in case there are a list of values to match with? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768093#M243588</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;use 'IN' instead of contains&lt;/P&gt;</description>
    <pubDate>Thu, 16 Sep 2021 12:00:17 GMT</pubDate>
    <dc:creator>Oligolas</dc:creator>
    <dc:date>2021-09-16T12:00:17Z</dc:date>
    <item>
      <title>How to use 'like' or 'contains' in case there are a list of values to match with?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768080#M243580</link>
      <description>&lt;P&gt;I have two datasets A and B. Table A contains a list of Keywords and Table B contains a list of Merchant Names.&lt;/P&gt;
&lt;P&gt;I have to create a table which will have all those observations from table B where the Merchant Name in table B contains any of the Keywords present in table A.&lt;/P&gt;
&lt;P&gt;Usually when I have a handful of keywords I do a wildcard search like this:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data B1;
Set B (where=( merchant_name like "%keyword1%"
or merchant_name like "%keyword2%"));
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But because I have a long list of keywords in this case how do I approach this? Will "like/contains" work in this case?&amp;nbsp; Is this the correct way?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql;
create table B1 as
select * from B where merchant_name contains (select distinct Keyword from A);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Shradha&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 10:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768080#M243580</guid>
      <dc:creator>Shradha1</dc:creator>
      <dc:date>2021-09-16T10:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'like' or 'contains' in case there are a list of values to match with?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768093#M243588</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;use 'IN' instead of contains&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 12:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768093#M243588</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-09-16T12:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'like' or 'contains' in case there are a list of values to match with?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768095#M243589</link>
      <description>But the merchants names in dataset B may not be exactly the same as the keywords. For example the merchant name can be 'Amazon.com' but by keyword list may have 'Amazon', 'Amazon Pay' etc.&lt;BR /&gt;In this case I would want the observation  'Amazon.com' to be selected in the new table B1.&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Sep 2021 12:11:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768095#M243589</guid>
      <dc:creator>Shradha1</dc:creator>
      <dc:date>2021-09-16T12:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'like' or 'contains' in case there are a list of values to match with?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768097#M243591</link>
      <description>&lt;P&gt;Use the EXISTS functionality of SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table B1 as
  select * from B 
  where exists (select 1 from A where find(B.merchant_name,A.Keyword,'it'))
;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Sep 2021 12:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768097#M243591</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-16T12:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'like' or 'contains' in case there are a list of values to match with?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768098#M243592</link>
      <description>Proc sql;&lt;BR /&gt;create table B1 as&lt;BR /&gt;select * &lt;BR /&gt;  from B inner join A&lt;BR /&gt;   on merchant_name contains strip( Keyword );&lt;BR /&gt;quit;</description>
      <pubDate>Thu, 16 Sep 2021 12:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768098#M243592</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-16T12:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'like' or 'contains' in case there are a list of values to match with?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768099#M243593</link>
      <description>This worked. Thanks!&lt;BR /&gt;Is there any way this can be incorporated within an Case When statement also?&lt;BR /&gt;Like 'Case when merchant_name contains (select distinct Keyword from A) then 1 else 0 end as flag'</description>
      <pubDate>Thu, 16 Sep 2021 12:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768099#M243593</guid>
      <dc:creator>Shradha1</dc:creator>
      <dc:date>2021-09-16T12:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to use 'like' or 'contains' in case there are a list of values to match with?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768147#M243614</link>
      <description>&lt;P&gt;If you want to flag the records rather than filter them you can try this method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*This is an example of how to search through a list of terms and see if a field contains any of the values*/

*Make fake data to show example;
*terms to search for;
data terms; 
set sashelp.baseball (obs=5);
search_term = substr(team,1,3);
keep search_term;;
run;
    
*main data set that will be searched;
data test; 
set sashelp.baseball;
run;


/*General process to the solution*/
******************************************************************************************
1. Store the number of terms in a macro variable to assign the length of arrays
2. Load terms to search into a temporary array
3. Loop through for each word and search the terms
4. Exit loop if you find the term to help speed up the process
******************************************************************************************;



/*1*/
proc sql noprint;
select count(*) into :num_search_terms from terms;
quit;

%put &amp;amp;num_search_terms.;



data flagged;

*declare array;
array _search(&amp;amp;num_search_terms.) $ _temporary_;

/*2*/
*load array into memory;
   if _n_ = 1 then do j=1 to &amp;amp;num_search_terms.;
   set terms;
   _search(j) = search_term;
   end;
 
 set test;
 
 *set flag to 0 for initial start;
 flag = 0;

/*3*/
*loop through and craete flag;
do i=1 to &amp;amp;num_search_terms. while(flag=0); /*4*/
   if find(team, _search(i), 'it')&amp;gt;0 then flag=1;
end;

drop i j search_term ;

run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Sep 2021 14:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-like-or-contains-in-case-there-are-a-list-of-values/m-p/768147#M243614</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-16T14:29:19Z</dc:date>
    </item>
  </channel>
</rss>

