<?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 multiple or comparison in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263268#M51512</link>
    <description>&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="votecell"&gt;
&lt;DIV class="vote"&gt;&lt;A class="vote-down-off" title="This question does not show any research effort; it is unclear or not useful" target="_blank"&gt;&lt;BR /&gt;&lt;/A&gt;
&lt;DIV class="favoritecount"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;TD class="postcell"&gt;
&lt;DIV&gt;
&lt;DIV class="post-text"&gt;
&lt;P&gt;I have a group of variables , say b1-b30 and i need to test same condition on same variables among themselves like, if b1='a' or b2='a' or b3='a'.. and so on. is there any solution in SAS macros or using of sas arrays to do this task to avoid writing this explicitly. sample code is like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;data test;
    input d1 d2 d3 d4 d5 ;
cards;
1 2 1 1 0
2 3 1 0 0 
0 0 0 1 0
0 2 1 0 2
0 4 0 2 2
0 0 0 0 3
;
run;

data want;
    set test;
    if d1=1 or d2=1 or d3=1 or d4=1 then flag=1;
    else flag=0;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so i have around 50 variable , to test same condition and flag it .&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
    <pubDate>Tue, 12 Apr 2016 17:01:56 GMT</pubDate>
    <dc:creator>ved_sas2014</dc:creator>
    <dc:date>2016-04-12T17:01:56Z</dc:date>
    <item>
      <title>multiple or comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263268#M51512</link>
      <description>&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="votecell"&gt;
&lt;DIV class="vote"&gt;&lt;A class="vote-down-off" title="This question does not show any research effort; it is unclear or not useful" target="_blank"&gt;&lt;BR /&gt;&lt;/A&gt;
&lt;DIV class="favoritecount"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;TD class="postcell"&gt;
&lt;DIV&gt;
&lt;DIV class="post-text"&gt;
&lt;P&gt;I have a group of variables , say b1-b30 and i need to test same condition on same variables among themselves like, if b1='a' or b2='a' or b3='a'.. and so on. is there any solution in SAS macros or using of sas arrays to do this task to avoid writing this explicitly. sample code is like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;data test;
    input d1 d2 d3 d4 d5 ;
cards;
1 2 1 1 0
2 3 1 0 0 
0 0 0 1 0
0 2 1 0 2
0 4 0 2 2
0 0 0 0 3
;
run;

data want;
    set test;
    if d1=1 or d2=1 or d3=1 or d4=1 then flag=1;
    else flag=0;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so i have around 50 variable , to test same condition and flag it .&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 12 Apr 2016 17:01:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263268#M51512</guid>
      <dc:creator>ved_sas2014</dc:creator>
      <dc:date>2016-04-12T17:01:56Z</dc:date>
    </item>
    <item>
      <title>Re: multiple or comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263274#M51514</link>
      <description>&lt;P&gt;data want(drop=i);&lt;/P&gt;
&lt;P&gt;set test;&lt;BR /&gt; flag=0;&lt;BR /&gt; array d(*) d:;&lt;BR /&gt; do i=1 to dim(d);&lt;BR /&gt; if d(i)=1 then flag=1;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 17:14:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263274#M51514</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2016-04-12T17:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: multiple or comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263276#M51516</link>
      <description>&lt;P&gt;Hi , thanks for quick reply, is this doing OR comparison among the variables? kindly explain and also in case we want to use "AND" operator, then how will it work&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 17:23:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263276#M51516</guid>
      <dc:creator>ved_sas2014</dc:creator>
      <dc:date>2016-04-12T17:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: multiple or comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263278#M51517</link>
      <description>&lt;P&gt;Yes, this is doing OR comparison. This says if any of the d variable equals to 1 then flag will be assigned a value of 1 and 0 otherwise.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 17:20:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263278#M51517</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2016-04-12T17:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: multiple or comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263280#M51519</link>
      <description>&lt;P&gt;The code provided by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/42042"&gt;@stat_sas﻿&lt;/a&gt;&amp;nbsp;assigns a default value of 0 to the flag (the Else assignment in the original post). Then it tests each variable in the array for the test value. If any of them match then the flag is set to 1.&lt;/P&gt;
&lt;P&gt;So it will provide the equivalent of&amp;nbsp; var1=1 or var2=1 or ..;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 17:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263280#M51519</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-12T17:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: multiple or comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263282#M51520</link>
      <description>&lt;P&gt;thanks @ballarw . just curious to know, if in case we have "and " operator&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 17:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263282#M51520</guid>
      <dc:creator>ved_sas2014</dc:creator>
      <dc:date>2016-04-12T17:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: multiple or comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263302#M51523</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32299"&gt;@ved_sas2014﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I may step in here: Sure, a slight modification of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/42042"&gt;@stat_sas﻿&lt;/a&gt;'s code could be used to set FLAG=1 if (and only if) the condition d&lt;EM&gt;i&lt;/EM&gt;=1 is true for &lt;EM&gt;all&lt;/EM&gt; &lt;EM&gt;i&lt;/EM&gt;=1, ..., 5 (edit: and FLAG=0 otherwise):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2(drop=i);
set test;
flag=1;
array d(*) d:;
do i=1 to dim(d);
  if d(i)~=1 then flag=0;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This makes use of the fact that&lt;/P&gt;
&lt;PRE&gt;(d1=1 and d2=1 and ... d5=1)&lt;/PRE&gt;
&lt;P&gt;is logically equivalent to&lt;/P&gt;
&lt;PRE&gt;not (d1~=1 or d2~=1 or ... d5~=1)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 18:55:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263302#M51523</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-12T18:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: multiple or comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263304#M51524</link>
      <description>&lt;P&gt;Here is an alternative solution to your original question: You can apply the IN operator to an array.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set test;
array d d:;  /* Your IF condition rather suggests: array d d1-d4; */
flag = 1 in d;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The condition "1 in d" (meaning that 1 is contained in the set {d(1), d(2), ...}, where the last element in the set depends on the array definition, see above) evaluates to 1 (true) or 0 (false).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 18:53:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263304#M51524</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-12T18:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: multiple or comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263315#M51528</link>
      <description>&lt;P&gt;Look at the WHICHN function. It doesn't return a 1/0 but the index of where the 1 is found.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For character variables there's a WHICHC function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;found=whichn(1, of d1-d100);&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Apr 2016 19:25:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263315#M51528</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-12T19:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: multiple or comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263326#M51530</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Look at the WHICHN function. It doesn't return a 1/0 but the index of where the 1 is found.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For character variables there's a WHICHC function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;found=whichn(1, of d1-d100);&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;... and if you need a 1/0 flag, you can simply write:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;flag = whichn(1, of d1-d100)&amp;gt;0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(or, still shorter: ... &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;of d:&lt;/FONT&gt;&lt;/STRONG&gt; ... if the variables whose names start with "d" are just d1, ..., d100).&lt;/P&gt;
&lt;P&gt;So, you can even save the ARRAY statement.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 19:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/multiple-or-comparison/m-p/263326#M51530</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-04-12T19:53:08Z</dc:date>
    </item>
  </channel>
</rss>

