<?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: In operator in array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/291998#M60528</link>
    <description>&lt;P&gt;Because one of the elements of the array M has the value 2 at that time.&lt;/P&gt;
&lt;P&gt;If you use "If 3 in M then m{i}=0"&amp;nbsp;note that all 3 elements will be assigned as 0 for the first observation.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Aug 2016 21:02:20 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-08-16T21:02:20Z</dc:date>
    <item>
      <title>In operator in array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/291993#M60523</link>
      <description>&lt;P&gt;Why the first observation of the X1 is recoded as 0?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input x1 x2 x3;
cards;
  1 2 3
  4 5 6
  7 8 9
  2 . 4
  ;
run;

data want (drop =  i);
	set test;
	array m{*} x:;
	do i = 1 to dim(m);
		if 2 in m then
			m{i} = 0;
		mean = mean(of m{*});
	end;
run;&lt;/CODE&gt;&lt;/PRE&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>Tue, 16 Aug 2016 20:31:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/291993#M60523</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-08-16T20:31:42Z</dc:date>
    </item>
    <item>
      <title>Re: In operator in array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/291997#M60527</link>
      <description>&lt;P&gt;The key to this program is here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if 2 in m then m{i} = 0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When i=1, m{i} refers to the first variable in the array, or X1.&amp;nbsp; That's how X1 gets set to 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The shocking (at least to me) part of this is that how SAS interprets "if 2 in m".&amp;nbsp; That actually is checking to see whether any of the array elements is equal to 2.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 20:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/291997#M60527</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-08-16T20:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: In operator in array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/291998#M60528</link>
      <description>&lt;P&gt;Because one of the elements of the array M has the value 2 at that time.&lt;/P&gt;
&lt;P&gt;If you use "If 3 in M then m{i}=0"&amp;nbsp;note that all 3 elements will be assigned as 0 for the first observation.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 21:02:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/291998#M60528</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-16T21:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: In operator in array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/292001#M60531</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;The key to this program is here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if 2 in m then m{i} = 0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When i=1, m{i} refers to the first variable in the array, or X1.&amp;nbsp; That's how X1 gets set to 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The shocking (at least to me) part of this is that how SAS interprets "if 2 in m".&amp;nbsp; That actually is checking to see whether any of the array elements is equal to 2.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Agreed about the surprise. Especially since IN doesn't normally use variables as the target. &lt;/P&gt;
&lt;P&gt;I did note that "if 2 in (M) ..." generates an error message. So we have yet another bit for arrays to examine.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 21:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/292001#M60531</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-16T21:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: In operator in array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/292004#M60534</link>
      <description>&lt;P&gt;You have recieved the answer that IN operator looks for the presence of 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another way to implement your idea is to get the index position of 2 in the array(using WHICHN() function). You are replacing it by zero if 2 is present. This means that zero will be counted as non-missing value in computing the mean. Further, the use of array does not need the do-loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If my presumtion is correct here is the way:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Revised Code to take care of repeated 2s in the Array.&lt;BR /&gt;&lt;BR /&gt;data test;&lt;BR /&gt;input x1 x2 x3;&lt;BR /&gt;cards;&lt;BR /&gt; 1 2 3&lt;BR /&gt; 4 5 6&lt;BR /&gt; 2 8 2&lt;BR /&gt; 2 . 4&lt;BR /&gt; ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want (drop = w);&lt;BR /&gt; set test;&lt;BR /&gt; array m[*] x:;&lt;BR /&gt; do i = 1 to dim(m);&lt;BR /&gt; w = whichn(2, of m[*]);&lt;BR /&gt; if w then m[w] = .;&lt;BR /&gt; end; &lt;BR /&gt; mean = mean(of m[*]);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The below code can replace one time.&lt;BR /&gt;&lt;BR /&gt;data want (drop =  w);
	set test;
	array m[*] x:;
   w = whichn(2, of m[*]);
   if w then m[w] = .; 
	mean = mean(of m[*]);
run;
proc print data = want;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have replaced 2 by a missing value for the count of non_missing values in the array. If you need that zero to be counted, it is just place 0 instead of missing value.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 23:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/292004#M60534</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-08-16T23:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: In operator in array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/292190#M60600</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17813"&gt;@KachiM﻿&lt;/a&gt;&amp;nbsp;Thanks. This is helpful.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 14:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/292190#M60600</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-08-17T14:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: In operator in array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/292193#M60602</link>
      <description>&lt;P&gt;You still need a loop to handle multiple variables with a value&amp;nbsp;of 2 in the array.&lt;/P&gt;
&lt;P&gt;But instead of iterative DO loop you can use a DO WHILE loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set test;
  array m x:;
  do until (w=0);
    w = whichn(2, of m(*));
    if w then m(w) = .; 
  end;
  mean = mean(of m(*));
  drop w;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Aug 2016 14:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/In-operator-in-array/m-p/292193#M60602</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-08-17T14:18:57Z</dc:date>
    </item>
  </channel>
</rss>

