<?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 do we apply where condition when there are multiple values in one column separated by &amp;amp;&amp;amp; in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-do-we-apply-where-condition-when-there-are-multiple-values/m-p/885406#M349863</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where not find(purpose,"construction") and not find(purpose,"purchase")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Expand for other exceptions as needed.&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jul 2023 07:20:01 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-07-19T07:20:01Z</dc:date>
    <item>
      <title>how do we apply where condition when there are multiple values in one column separated by &amp;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-we-apply-where-condition-when-there-are-multiple-values/m-p/885394#M349857</link>
      <description>&lt;P&gt;I've a DS that can have multiple values in purpose column : it can be any combination of 'build', 'buy', 'construction', 'purchase' and so on....&lt;/P&gt;&lt;P&gt;I only need to keep the record if the purpose column has 'buy' or 'build' values or combination of both, but &lt;STRONG&gt;not&lt;/STRONG&gt; the others or even a combination of buy or build with any other values. For instance"&lt;/P&gt;&lt;P&gt;Acceptable values are: buy, build, buy &amp;amp; build, build &amp;amp; buy&lt;/P&gt;&lt;P&gt;Unacceptable values: construction, purchase, buy &amp;amp; construction, buy &amp;amp; purchase, build &amp;amp; construction, build &amp;amp; purchase&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I go about coding that in sas please ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's easy to write where condition when there is only one value in column but for multiple values, I'm needing some help thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2023 04:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-we-apply-where-condition-when-there-are-multiple-values/m-p/885394#M349857</guid>
      <dc:creator>waliaa</dc:creator>
      <dc:date>2023-07-19T04:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: how do we apply where condition when there are multiple values in one column separated by &amp;&amp;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-we-apply-where-condition-when-there-are-multiple-values/m-p/885406#M349863</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where not find(purpose,"construction") and not find(purpose,"purchase")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Expand for other exceptions as needed.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2023 07:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-we-apply-where-condition-when-there-are-multiple-values/m-p/885406#M349863</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-07-19T07:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: how do we apply where condition when there are multiple values in one column separated by &amp;&amp;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-we-apply-where-condition-when-there-are-multiple-values/m-p/885408#M349865</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'd use the divide and conquer tactic for this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd;
input order ~ $200.;
datalines;
"' build ', 'buy ', 'construction', 'purchase' "
build
;
run;

data want1;
   set have;
   length hasBuild hasBuy hasConstruction hasPurchase 8;
   
   array _orders hasBuild hasBuy hasConstruction hasPurchase;
   do over _orders;
      if findw(order,substr(vname(_orders),4),'','IP') then _orders=1;
   end;
run;
proc print;run;

data want2;
   set want1;
   where hasBuy;&lt;BR /&gt;*drop has:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jul 2023 07:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-we-apply-where-condition-when-there-are-multiple-values/m-p/885408#M349865</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-07-19T07:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: how do we apply where condition when there are multiple values in one column separated by &amp;&amp;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-we-apply-where-condition-when-there-are-multiple-values/m-p/885497#M349907</link>
      <description>&lt;P&gt;You want to keep instances where, in the variable PURPOSE, at least one of a set of words is present, but no words outside the set is present.&amp;nbsp; Terms can be separated by ampersands and blanks, per your example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you have only two desired terms, you can do a simple list of purpose values.&amp;nbsp; This is not nicely scalable to more than two or three terms:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have ;
  if upcase(compress(purpose,' &amp;amp;')) in ('BUILD','BUY','BUILDBUY','BUYBUILD') then found=1;
  else found=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have comma separators in PURPOSE, then add it to the second argument of the compress function.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2023 17:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-we-apply-where-condition-when-there-are-multiple-values/m-p/885497#M349907</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-07-19T17:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: how do we apply where condition when there are multiple values in one column separated by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-we-apply-where-condition-when-there-are-multiple-values/m-p/885517#M349918</link>
      <description>&lt;P&gt;Personally I am of the one variable one value school. EVERY time I have had data with multiple values in a single "variable" any attempt at using that one variable is so much work and starts from scratch for each use that it is just not worth maintaining. One data set I work with has 2 variables that can have as many as 50 codes and are not even nicely separated by any character, just a series of digits that have to be parsed as pairs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the list of possible values is known and doesn't change frequently then I would suggest creating a series of variables that are 1, for that value is present, and 0 otherwise. A minor variation of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/77163"&gt;@Oligolas&lt;/a&gt; code would assign the 0 values in the known list that were not present.&lt;/P&gt;
&lt;P&gt;Then your "where" or other conditions become relatively easy.&lt;/P&gt;
&lt;P&gt;Consider if you have variables created named Build, Buy, Construction, Purchase (demolish, renovate, whatever) so coded.&lt;/P&gt;
&lt;P&gt;If you want to know if &lt;STRONG&gt;any&lt;/STRONG&gt; of the given the variables have a value of 1 then&lt;/P&gt;
&lt;P&gt;where max(Build, Buy) =1;&lt;/P&gt;
&lt;P&gt;If want to find records where &lt;STRONG&gt;all&lt;/STRONG&gt; of a list of variables are 1:&lt;/P&gt;
&lt;P&gt;Where sum(Build, Buy,Renovate)=3; (3 variables values of 1 or 0 then you only get a sum of 3 when all are 1).&lt;/P&gt;
&lt;P&gt;If you want to find records where &lt;STRONG&gt;none &lt;/STRONG&gt;of the values are 1:&lt;/P&gt;
&lt;P&gt;Where max(build,buy,construction)=0;&lt;/P&gt;
&lt;P&gt;If you want to find records where all of the values are the same, 1 or 0 but all the same:&lt;/P&gt;
&lt;P&gt;Where range(build,buy,purchase)=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or add temporary analysis variables using the functions with selected variables.&lt;/P&gt;
&lt;P&gt;Also note that mean of a list of such variables gives the percent of 1 in decimal form.&lt;/P&gt;
&lt;P&gt;SAS internally uses 1 for 'true' and 0 for false so you can even reduce very simple conditions:&lt;/P&gt;
&lt;P&gt;Where buy;&lt;/P&gt;
&lt;P&gt;is the same as "Where buy=1"; when the variable Buy only takes values of 1,0 or possibly missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course you could combine conditions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would consider the coding if "buy" is really different than "purchase" then two variables but face value of the words I would doubt it.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 00:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-we-apply-where-condition-when-there-are-multiple-values/m-p/885517#M349918</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-07-20T00:53:56Z</dc:date>
    </item>
  </channel>
</rss>

