<?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: Multiple contains and list of words in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-contains-and-list-of-words/m-p/342492#M78534</link>
    <description>&lt;P&gt;Sure you can.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It depends, though, on what you want to achieve, what steps you do besides the proc sql and how clean you want your code to be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one quick'n'dirty example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
a = 'emil, Nordpole, richard, Theo'; b = 'something, somethingelse'; output;
a = 'sandman, emil, peter'; b = 'whatever'; output;
a = 'samuel'; b = 'anoterexample'; output;
a = 'stephany'; b = 'lookingforwordshere'; output;
run;

%macro quickndirty(varlist);
%let varlist = %upcase(&amp;amp;varlist.);
proc sql;
create table want as
select * from have
where 1=0
      %do i=1 %to %sysfunc(countw(&amp;amp;varlist.));
        %let next_name = %scan(&amp;amp;varlist., &amp;amp;i.);
        or upcase(a) contains "&amp;amp;next_name."
        or upcase(b) contains "&amp;amp;next_name."
      %end;
;quit;
%mend;

%let list = nordpole pet lookingforwords;
%quickndirty(&amp;amp;list.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think you will be able to apply this to your example.&lt;/P&gt;
&lt;P&gt;The "1=0" is necessary, because the first "or" would lead to an error otherwise. As I said, this is just a quick'n'dirty example to get you started.&lt;/P&gt;
&lt;P&gt;Notice, however, that this does not search for complete words, but rather for the part that you enter. In my example I wrote "pet" instead of "peter", yet it still finds "peter". So unclear identifiers and typos might lead to unexpected results!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More sophisticated solutions might be found, but then again, it depends on your requirements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might also consider using ID's instead of names and follow the example procided &lt;A href="https://communities.sas.com/t5/General-SAS-Programming/How-to-combine-contains-and-in-a-list-operator-in-proc-sql/td-p/121688" target="_blank"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Michael&lt;/P&gt;</description>
    <pubDate>Mon, 20 Mar 2017 08:56:11 GMT</pubDate>
    <dc:creator>mfab</dc:creator>
    <dc:date>2017-03-20T08:56:11Z</dc:date>
    <item>
      <title>Multiple contains and list of words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-contains-and-list-of-words/m-p/157676#M30767</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the following query that search for three words in two columns :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; CREATE TABLE test AS &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; SELECT t1.*&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM mylib.mytable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE upcase(t1.c1) contains "BOB" or &lt;/P&gt;&lt;P&gt;upcase(t1.c1) contains "ROBERT" or &lt;/P&gt;&lt;P&gt;upcase(t1.c1) contains "LUCY" or &lt;/P&gt;&lt;P&gt;upcase(t1.c2) contains "BOB" or &lt;/P&gt;&lt;P&gt;upcase(t1.c2) contains "ROBERT" or &lt;/P&gt;&lt;P&gt;upcase(t1.c2) contains "LUCY"&lt;/P&gt;&lt;P&gt;;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to be able to replace this by a macro-variable where I store a list of all the words I want to search and a macro that call that list and the column I want it to apply to&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i.e :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%LET MY_WORDS = ("BOB","ROBERT","LUCY")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mymacro(t1,c1,c2,&amp;amp;my_words)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is this something that can be done?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help and time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Mar 2014 19:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-contains-and-list-of-words/m-p/157676#M30767</guid>
      <dc:creator>nicnad</dc:creator>
      <dc:date>2014-03-26T19:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple contains and list of words</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-contains-and-list-of-words/m-p/342492#M78534</link>
      <description>&lt;P&gt;Sure you can.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It depends, though, on what you want to achieve, what steps you do besides the proc sql and how clean you want your code to be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one quick'n'dirty example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
a = 'emil, Nordpole, richard, Theo'; b = 'something, somethingelse'; output;
a = 'sandman, emil, peter'; b = 'whatever'; output;
a = 'samuel'; b = 'anoterexample'; output;
a = 'stephany'; b = 'lookingforwordshere'; output;
run;

%macro quickndirty(varlist);
%let varlist = %upcase(&amp;amp;varlist.);
proc sql;
create table want as
select * from have
where 1=0
      %do i=1 %to %sysfunc(countw(&amp;amp;varlist.));
        %let next_name = %scan(&amp;amp;varlist., &amp;amp;i.);
        or upcase(a) contains "&amp;amp;next_name."
        or upcase(b) contains "&amp;amp;next_name."
      %end;
;quit;
%mend;

%let list = nordpole pet lookingforwords;
%quickndirty(&amp;amp;list.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think you will be able to apply this to your example.&lt;/P&gt;
&lt;P&gt;The "1=0" is necessary, because the first "or" would lead to an error otherwise. As I said, this is just a quick'n'dirty example to get you started.&lt;/P&gt;
&lt;P&gt;Notice, however, that this does not search for complete words, but rather for the part that you enter. In my example I wrote "pet" instead of "peter", yet it still finds "peter". So unclear identifiers and typos might lead to unexpected results!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More sophisticated solutions might be found, but then again, it depends on your requirements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might also consider using ID's instead of names and follow the example procided &lt;A href="https://communities.sas.com/t5/General-SAS-Programming/How-to-combine-contains-and-in-a-list-operator-in-proc-sql/td-p/121688" target="_blank"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Michael&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2017 08:56:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-contains-and-list-of-words/m-p/342492#M78534</guid>
      <dc:creator>mfab</dc:creator>
      <dc:date>2017-03-20T08:56:11Z</dc:date>
    </item>
  </channel>
</rss>

