<?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: Contains - multiple values selection in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/457660#M116050</link>
    <description>&lt;P&gt;Please assign the correct answer as solution so that others have it also.&lt;/P&gt;</description>
    <pubDate>Thu, 26 Apr 2018 10:05:14 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2018-04-26T10:05:14Z</dc:date>
    <item>
      <title>Contains - multiple values selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456148#M115514</link>
      <description>&lt;P&gt;Hello, i am a verry new and verry basic user, and i want to know if it possible to have different vallues in a where function following a contains cmd, ex:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=work.l2b1;&lt;BR /&gt;where F='DE' and A contains 'ciproflox' or&lt;BR /&gt;F='FR' and A contains 'OFLOX';&lt;BR /&gt;by J;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How i could put more values/prod names after contains, smth like this: contains 'cipro' 'ator' 'Ome' 'etc',&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I am trying to extract from a datat set only the lines that have country of incidence FR ( F=country) and&amp;nbsp;at least one from the product list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like i have mentioned i am verry new with SAS and i dont have a programmer background, i dont even know if contains can do what i want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THX.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 07:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456148#M115514</guid>
      <dc:creator>Ionut_Baciu</dc:creator>
      <dc:date>2018-04-21T07:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Contains - multiple values selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456150#M115516</link>
      <description>&lt;P&gt;If all of your coditions are a combination of F and A variables you can use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;where upcase(cat(F,A)) in ("DECIPROFLOX" , "FROFLOX" , ... );&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 07:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456150#M115516</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-04-21T07:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: Contains - multiple values selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456151#M115517</link>
      <description>&lt;P&gt;It will be easier for me to understand if its possible to have a string of values following a contains:&amp;nbsp;&lt;/P&gt;&lt;P&gt;contains A B C D E, and how exactly i writhe them so i wont get an error, because ive tried :&lt;/P&gt;&lt;P&gt;Contains ("A", "B", "C", "D")&amp;nbsp; and doesent work.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 08:11:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456151#M115517</guid>
      <dc:creator>Ionut_Baciu</dc:creator>
      <dc:date>2018-04-21T08:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: Contains - multiple values selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456164#M115521</link>
      <description>&lt;P&gt;Put your condition values into a dataset, and you can use contains or similar in a where condition of a SQL join.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 11:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456164#M115521</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-21T11:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Contains - multiple values selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456168#M115523</link>
      <description>&lt;P&gt;Unfortunately i dont know how to do that, 0 experience with sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if someone can tell me if is possible to have more then 1 observation after contains/like,&amp;nbsp;&lt;/P&gt;&lt;P&gt;example of what im looking for: like ('a', 'b', 'c'), btw i've tried this and is not working for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;My code is smth like :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=work.l2b1;&lt;BR /&gt;where F='DE' and A like ('%ciproflox%'; '%atorv%','%ola%');&lt;BR /&gt;by J;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i use&amp;nbsp;&lt;SPAN&gt;where F='DE' and A like '%ciproflox%'; it works, but i cant get at least 2 obs afther like, dont know how to group them&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 12:11:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456168#M115523</guid>
      <dc:creator>Baciu_Ionut</dc:creator>
      <dc:date>2018-04-21T12:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: Contains - multiple values selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456169#M115524</link>
      <description>&lt;P&gt;As much as I know there is no function like what you want.&lt;/P&gt;
&lt;P&gt;but you can do it using a macro program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;define the macro outside and before the step to run:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro check_for(varF=, varA=);
        %let n=%sysfunc(countw(&amp;amp;varA));&lt;BR /&gt;        %let varF = %upcase(&amp;amp;varF);&lt;BR /&gt;        %let varA = %upcase(&amp;amp;varA);

        if F = "&amp;amp;varF" and 
       %do i=1 %to &amp;amp;n;
              /* A contains... */&lt;BR /&gt;              findw(upcase(A) , "%scan(&amp;amp;varA,&amp;amp;i)") &lt;BR /&gt;           /* index(upcase(A) , "%scan(&amp;amp;varA,&amp;amp;i)") */    
              %if &amp;amp;i &amp;lt; &amp;amp;n %then %str( or );
       %end;&lt;BR /&gt;        then output;
%mend check_for;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; If you want the check for a substring, not a whole word, then replace the &lt;STRONG&gt;FINDW&lt;/STRONG&gt; function by&amp;nbsp;&lt;STRONG&gt;INDEX&lt;/STRONG&gt; function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;creating a test data and using the macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    F="DE"; A="any ciproflox med"; output;
    F="DE"; A="any non oflox med"; output;
    F="FR"; A="OFLOX or BFLOX or CFLOX"; output;
    F="FR"; A="eflox or dflox oe Fflox"; output;
;
run;

data result;
 set test;
   %check_for(varF=DE, varA=cipro);
   %check_for(varF=FR, varA=oflox fflox);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Run both functions&amp;nbsp; - with FINDW and with INDEX and compare results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 12:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456169#M115524</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-04-21T12:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Contains - multiple values selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456176#M115525</link>
      <description>&lt;P&gt;Tank yiu verry much, i have managed to aplly your macro to my dataset, but im still having some problems:&lt;/P&gt;&lt;P&gt;1 one is that when A have more then 1 observation (Ex: A=ciprofloxcin atorvastatin) even if F=DE (F=country, DE=Germany), i still get results from outside DE (ex IT, FR, countries were the second product "atorvastatine" is present).&lt;/P&gt;&lt;P&gt;the code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data result;&lt;BR /&gt;set l2b1;&lt;BR /&gt;%check_for(varF=DE, varA=ciprofloxacin atorvastatin);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=work.result;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. i would like to be abble to search for a part of the word not exactly the word Ex; %ator not atorvastatin, so to get any obs that start with ator.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3.&amp;nbsp;I dident understand the comment&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; &lt;SPAN class="token comment"&gt;/* A contains... */&lt;/SPAN&gt; was that put there to explain that &lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;findw&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;upcase&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;A&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;"%scan(&amp;amp;varA,&amp;amp;i)"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;        or    &lt;SPAN class="token comment"&gt;/* index(upcase(A) , "%scan(&amp;amp;varA,&amp;amp;i)") */&lt;/SPAN&gt;  was the cointain function i was looking for.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Thank you.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 13:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456176#M115525</guid>
      <dc:creator>Baciu_Ionut</dc:creator>
      <dc:date>2018-04-21T13:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: Contains - multiple values selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456178#M115526</link>
      <description>&lt;P&gt;There is no simple function/operator for that type of test.&lt;/P&gt;
&lt;P&gt;I would just start by combining multiple tests.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=work.l2b1  out=want;
  where (F='DE'
         and (lowcase(A) contains 'ciproflox'
           or lowcase(A) contains 'cipro'
             )
        )
   or (F='FR' and A contains 'OFLOX')
  ;
  by J;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are familiar with regular expressions you might be able to use one or more of the prx.... functions to do your search.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 14:13:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456178#M115526</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-21T14:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Contains - multiple values selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456184#M115527</link>
      <description>&lt;P&gt;I'll start with your third note - the comment means that next two lines are are supposed to do what you want.&lt;/P&gt;
&lt;P&gt;As there is no function CONTAIN (nor CONTAINS) I can use each of the two other functions:&lt;/P&gt;
&lt;P&gt;FINDW - search for a whole word limitted by spaces.&lt;/P&gt;
&lt;P&gt;INDEX - search for a substring.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; A = "ciproflox".&lt;/P&gt;
&lt;P&gt;&amp;nbsp; result1 = findw(A , "cipro")&amp;nbsp; will be 0 (means not found).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; result2 = index(A, "cipro")&amp;nbsp; &amp;nbsp;will be 1 (the position where the substring starts).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems that you need the INDEX variation of the macro program.&lt;/P&gt;
&lt;P&gt;I have added ( ) to fix the problem of getting non DE observations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro check_for(varF=, varA=);
        %let n=%sysfunc(countw(&amp;amp;varA));        &lt;BR /&gt;        %let varF = %upcase(&amp;amp;varF);        &lt;BR /&gt;        %let varA = %upcase(&amp;amp;varA);

        if F = "&amp;amp;varF" and (
       %do i=1 %to &amp;amp;n;
              index(upcase(A) , "%scan(&amp;amp;varA,&amp;amp;i)") 
              %if &amp;amp;i &amp;lt; &amp;amp;n %then %str( or );
       %end;  )   then output;
%mend check_for;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I suggest that you add&amp;nbsp;&lt;STRONG&gt;options mprint;&lt;/STRONG&gt; in your code and look at the log to see what have this macro program done:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;
data result;
  set l2b1;
       %check_for(varF=DE, varA=ciprofloxacin atorvastatin);
run;
options nomprint;

proc print data=work.result;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Apr 2018 14:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/456184#M115527</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-04-21T14:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: Contains - multiple values selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/457627#M116038</link>
      <description>&lt;P&gt;Sry for my late reply, I wanted to tank you and to say i've managed to make the macro work for my dataset. Tank you all for the support. Have a good and blessed day.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 08:16:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/457627#M116038</guid>
      <dc:creator>Baciu_Ionut</dc:creator>
      <dc:date>2018-04-26T08:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Contains - multiple values selection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/457660#M116050</link>
      <description>&lt;P&gt;Please assign the correct answer as solution so that others have it also.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 10:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Contains-multiple-values-selection/m-p/457660#M116050</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-04-26T10:05:14Z</dc:date>
    </item>
  </channel>
</rss>

