<?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: Using Contains Statement with a Macro in Proc SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/402007#M97584</link>
    <description>&lt;P&gt;Yes this code does work when hard coded. I might have to just limit them to 3 entries or something similar to what you have.&amp;nbsp; Thanks&lt;/P&gt;</description>
    <pubDate>Fri, 06 Oct 2017 23:20:20 GMT</pubDate>
    <dc:creator>cbrotz</dc:creator>
    <dc:date>2017-10-06T23:20:20Z</dc:date>
    <item>
      <title>Using Contains Statement with a Macro in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/401931#M97545</link>
      <description>&lt;P&gt;Is it possible to use the Contains statement together with a macro list with more than one lookup?&amp;nbsp; I am trying do multiple lookups using partial strings.&amp;nbsp;&amp;nbsp; It works if just one selection is made but not more than one....If I just send through "ASSORTED" for example, I get all Mat_Desc that contain the word "Assorted".&amp;nbsp; I would like to do a lookup on all that are i the list....I tried the LIKE statement and was not having much luck with that either....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;PROC SQL;&lt;BR /&gt;38&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CREATE TABLE WORK.MATERIALS_4 AS&lt;BR /&gt;39&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT t1. *&lt;BR /&gt;40&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;41&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM BIRD.V_MATERIALS t1&lt;BR /&gt;42&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; where t1.MAT_DESC CONTAINS (&amp;amp;value_list6);&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;NOTE: Line generated by the macro variable "VALUE_LIST6".&lt;BR /&gt;42&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "ASSORTED","POSTERS"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, ), *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, BETWEEN,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CONTAINS, EQ, EQT, GE, GET, GT, GTT, IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=. &amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 20:35:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/401931#M97545</guid>
      <dc:creator>cbrotz</dc:creator>
      <dc:date>2017-10-06T20:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using Contains Statement with a Macro in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/401983#M97577</link>
      <description>&lt;P&gt;Contains want to compare a single value&lt;/P&gt;
&lt;P&gt;you would want something like&lt;/P&gt;
&lt;PRE&gt;where  t1.MAT_DESC CONTAINS (&amp;amp;value1) 
   or  t1.MAT_DESC CONTAINS (&amp;amp;value2) 
   or  t1.MAT_DESC CONTAINS (&amp;amp;value3)
; 
 &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you try hardcoding an example of this with two values and no macro variable before attempting this code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is inside an actual macro block defined with %macro&amp;nbsp; ... %mend statements you could count the number of elements in &amp;amp;value list and build the "or" statements for each value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If Mat_desc is supposed to actually be "ASSORTED" and doesn't have values like "ASSORTED HARDWARE" you could us the IN comparison.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 22:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/401983#M97577</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-06T22:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using Contains Statement with a Macro in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/402007#M97584</link>
      <description>&lt;P&gt;Yes this code does work when hard coded. I might have to just limit them to 3 entries or something similar to what you have.&amp;nbsp; Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 23:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/402007#M97584</guid>
      <dc:creator>cbrotz</dc:creator>
      <dc:date>2017-10-06T23:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using Contains Statement with a Macro in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/402031#M97590</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/112131"&gt;@cbrotz&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Just a thought in case you're passing in the values via a prompt: It's sometimes necessary to %unquote() the string for downstream processing with code as below:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;....where t1.MAT_DESC CONTAINS (&lt;FONT color="#FF0000"&gt;%unquote(&lt;/FONT&gt;&amp;amp;value_list6&lt;FONT color="#FF0000"&gt;)&lt;/FONT&gt;)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2017 03:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/402031#M97590</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-10-07T03:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using Contains Statement with a Macro in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/402036#M97593</link>
      <description>&lt;P&gt;Can you explain a little better what you are trying to do?&lt;/P&gt;
&lt;P&gt;The CONTAIN operator does NOT support multiple values at once. You can NOT write a statement like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;name contains ('a','b')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to pass a list of values into a SAS macro then you could use macro code to loop over the items in that list and generate a series of CONTAIN clauses connected by OR. So something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;name contains 'a' or name contains 'b'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For example you might create a macro like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro contains(var,values);
%local i sep ;
%do i=1 %to %sysfunc(countw(&amp;amp;values,%str(,),mq));
&amp;amp;sep &amp;amp;var contains %scan(&amp;amp;values,&amp;amp;i,%str(,),mq)
%let sep=or;
%end;
%mend contains;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So then you could use it like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
 select * from sashelp.class
 where %contains(name,%str('a','b'))
 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2017 04:00:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/402036#M97593</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-07T04:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using Contains Statement with a Macro in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/402408#M97703</link>
      <description>&lt;P&gt;That is really good to know.&amp;nbsp; I already ran into this problem and ended up writing a SAS step to fix. Thanks for next time -&amp;nbsp; it will save me coding!&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 15:48:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/402408#M97703</guid>
      <dc:creator>cbrotz</dc:creator>
      <dc:date>2017-10-09T15:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using Contains Statement with a Macro in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/402412#M97704</link>
      <description>&lt;P&gt;Hi Tom,&amp;nbsp; Thanks again for your help....yes after they started using the prompts, they asked if they could enter parts of descriptions.....The list of material descriptions is too long and I cannot create a list for them to pick from as I did with other data&amp;nbsp; - SAS won't do a lookup past 5000 or so?&amp;nbsp; That makes sense.&amp;nbsp; I can't imagine it is helpful to have to scroll through thousands of entries....&amp;nbsp; Anyway, I am limiting them to 10 descriptions or partial descriptions and coded for 10.....we will see how that goes.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 15:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Contains-Statement-with-a-Macro-in-Proc-SQL/m-p/402412#M97704</guid>
      <dc:creator>cbrotz</dc:creator>
      <dc:date>2017-10-09T15:55:44Z</dc:date>
    </item>
  </channel>
</rss>

