<?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: Check if an array contains a value. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-if-an-array-contains-a-value/m-p/723098#M224339</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150926"&gt;@kk13&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=f i);
set z;
array a a1-a4;
array b b1-b4;
f=whichn(1, of a{*});
HAS=0;
if f then do;
  do i=f to dim(a) until(check1&amp;lt;=b{i}&amp;lt;=check2);
  end;
  if i&amp;lt;=dim(a) then HAS=1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 03 Mar 2021 09:33:09 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2021-03-03T09:33:09Z</dc:date>
    <item>
      <title>Check if an array contains a value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-an-array-contains-a-value/m-p/723092#M224333</link>
      <description>&lt;P&gt;I would like to check if the array "a" contains any 1s.&amp;nbsp; The check1, check2, and "b" array are used to determine the dimension number I need to check in array "a."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For id=1, check1=11 and check2=17.&amp;nbsp; I found that 11&amp;lt;=b{i}&amp;lt;=17 is at i=2 (b2=15).&amp;nbsp; Hence, I need to check if a1 through a2 contains any 1s.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; z;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; id a1-a4 b1-b4 check1 check2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 1 . . 1 10 15 18 20 11 17&lt;/P&gt;&lt;P&gt;2 . . 1 1 17 18 19 21 16 18&lt;/P&gt;&lt;P&gt;3 . . . 1 18 19 21 22 16 23&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; id a1-a4 b1-b4 check1 check2 HAS;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 1 . . 1 10 15 18 20 11 17 1&lt;/P&gt;&lt;P&gt;2 . . 1 1 17 18 19 21 16 18 0&lt;/P&gt;&lt;P&gt;3 . . . 1 18 19 21 22 23 23 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; z1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; z;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;array&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a a1-a4;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;array&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; b b1-b4;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;to&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; dim(a);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; check1&amp;lt;=b{i}&amp;lt;=check2 &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;then&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;j=i;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 08:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-an-array-contains-a-value/m-p/723092#M224333</guid>
      <dc:creator>kk13</dc:creator>
      <dc:date>2021-03-03T08:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Check if an array contains a value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-an-array-contains-a-value/m-p/723096#M224337</link>
      <description>&lt;P&gt;Sorry, but i don't understand the logic that you want applied: why is has = 0 when id = 2?&lt;/P&gt;
&lt;P&gt;Please re-check the data you have posted, the values for check1 and check2 in "want" don't match those in "z". Also please post code using the "insert sas code" button.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 09:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-an-array-contains-a-value/m-p/723096#M224337</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-03-03T09:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Check if an array contains a value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-an-array-contains-a-value/m-p/723097#M224338</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data z;
input id a1-a4 b1-b4 check1 check2;
datalines;
1 1 . . 1 10 15 18 20 11 17
2 . . 1 1 17 18 19 21 16 18
3 . . . 1 18 19 21 22 16 23
;

data want(drop = idx);
   set z;
   array a a1-a4;
   array b b1-b4;
   has = 0;

   do over b;
      if check1 &amp;lt;= b &amp;lt;= check2 then idx = _I_;
   end;

   do over a;
      if _I_ &amp;gt; idx then leave;
      if a = 1 then has = 1;
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;id a1 a2 a3 a4 b1 b2 b3 b4 check1 check2 has 
1  1  .  .  1  10 15 18 20 11     17     1 
2  .  .  1  1  17 18 19 21 16     18     0 
3  .  .  .  1  18 19 21 22 16     23     1 &lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Mar 2021 09:33:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-an-array-contains-a-value/m-p/723097#M224338</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-03-03T09:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Check if an array contains a value.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-an-array-contains-a-value/m-p/723098#M224339</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150926"&gt;@kk13&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=f i);
set z;
array a a1-a4;
array b b1-b4;
f=whichn(1, of a{*});
HAS=0;
if f then do;
  do i=f to dim(a) until(check1&amp;lt;=b{i}&amp;lt;=check2);
  end;
  if i&amp;lt;=dim(a) then HAS=1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Mar 2021 09:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-an-array-contains-a-value/m-p/723098#M224339</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-03-03T09:33:09Z</dc:date>
    </item>
  </channel>
</rss>

