<?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: Array Puzzle in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276358#M55360</link>
    <description>&lt;P&gt;The inital values for the array implies RETAIN of those variables.&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jun 2016 19:27:27 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2016-06-09T19:27:27Z</dc:date>
    <item>
      <title>Array Puzzle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276357#M55359</link>
      <description>&lt;P&gt;I have two variables, X and Y, plus another variable S. X and Y are integers in the range 1-7. S is a character variable that takes the value '1' and some others. I want to create&amp;nbsp;a series of flags, A1-A4, according to these rules.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;IF S='1', set the flag corresponding to the larger of X and Y, subject to the maximum of 4. For example, if X=1 and Y=2, then set A2 = 1, leaving the other flags equal to zero. If X=2 and Y=6, set A4=1, etc.&lt;/LI&gt;&lt;LI&gt;IF S is anything else, set the flag corresponding to Y, with the same maximum (ignore X&amp;nbsp;entirely).&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I first wrote this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Test;
	SET Source;
	ARRAY A[4] A1-A4 (0 0 0 0);
	IF S = '1' THEN
		A[MIN(4,MAX(X,Y))] = 1;
	ELSE
		A[MIN(4,Y)] = 1;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I read that, it should change only one of the A1-A4 flags for each record. But what I find is that ALL of the values of A1-A4 get set to 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I do this,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Test;
	SET Source;
	A1 = 0;
	A2 = 0;
	A3 = 0;
	A4 = 0;
	ARRAY A[4] A1-A4;
	IF S = '1' THEN
		A[MIN(4,MAX(X,Y))] = 1;
	ELSE
		A[MIN(4,Y)] = 1;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get what I want. What is the difference?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 19:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276357#M55359</guid>
      <dc:creator>Davanden</dc:creator>
      <dc:date>2016-06-09T19:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: Array Puzzle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276358#M55360</link>
      <description>&lt;P&gt;The inital values for the array implies RETAIN of those variables.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 19:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276358#M55360</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-06-09T19:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Array Puzzle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276380#M55368</link>
      <description>&lt;P&gt;ARRAY A[4] A1-A4 (0 0 0 0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;initialises the values only once: when the array is created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are 2 cases when array values are not reset in the data step loop: when they are temporary, and when their values are initialised.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 23:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276380#M55368</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-06-09T23:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Array Puzzle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276450#M55382</link>
      <description>&lt;P&gt;If it helps, you can shrink your if clauses:&lt;/P&gt;
&lt;PRE&gt;data source;
  s="1"; x=3; y=3; output;
  s="2"; x=1; y=6; output;
run;
data test;
  set source; 
  array a[4] (0 0 0 0);
  a[min(4,max(x,y))]=ifn(s='1',1,0);
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Jun 2016 09:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276450#M55382</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-10T09:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: Array Puzzle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276453#M55383</link>
      <description>Or a[min(4,max(x,y))]=(s='1');</description>
      <pubDate>Fri, 10 Jun 2016 09:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276453#M55383</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-06-10T09:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: Array Puzzle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276457#M55384</link>
      <description>&lt;P&gt;Side note: The specifiction of an initial value for &lt;EM&gt;one&lt;/EM&gt; array variable implies RETAIN for &lt;EM&gt;all&lt;/EM&gt; variables of the array, including those which are not initialized.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 10:06:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276457#M55384</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-06-10T10:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: Array Puzzle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276471#M55388</link>
      <description>&lt;P&gt;Thanks to all who replied. &amp;nbsp;I seldom use the ability to intialize arrays, and I see that there were implications of doing that which I didn't realize.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks also to those who showed me how to make the code more compact. &amp;nbsp;Those are clever uses of SAS functions. &amp;nbsp;I'm not sure if I will use them. &amp;nbsp;I fear that a few years from now, someone (possibly me) will look at the code and say, "What the heck does&amp;nbsp;&lt;EM&gt;that&lt;/EM&gt; do?" &amp;nbsp;I don't want my code to be more clever than my ability to understand it!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;--Dav&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 12:03:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Puzzle/m-p/276471#M55388</guid>
      <dc:creator>Davanden</dc:creator>
      <dc:date>2016-06-10T12:03:24Z</dc:date>
    </item>
  </channel>
</rss>

