<?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 array problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/array-problem/m-p/596079#M171580</link>
    <description>&lt;P&gt;Hi community,&lt;/P&gt;&lt;P&gt;I'm a SAS beginner and I need help with this question below.&amp;nbsp; a) shows error "&lt;SPAN&gt;Array subscript out of range at line 77 column 14" but I'm not sure how to correct it. b and c seem to have no problems but please correct me if I'm wrong. Thank you very much!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*2. What, if anything, is wrong with the following data step program fragments?&lt;/P&gt;&lt;PRE&gt;  a);
  data c;
   array x{20};
total=0;
do i=1 to 25 by 2;
   total=sum(x(i), total);
 end;
 
 

*b);
data d;
 array x{20};
    n=0;
    do i=1 to 25 by 2;
       n=n+1;
       total=sum(x(n), total);
     end;

 *c);
 do i=0.07 to 0.08;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 13 Oct 2019 15:56:36 GMT</pubDate>
    <dc:creator>Amy0223</dc:creator>
    <dc:date>2019-10-13T15:56:36Z</dc:date>
    <item>
      <title>array problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-problem/m-p/596079#M171580</link>
      <description>&lt;P&gt;Hi community,&lt;/P&gt;&lt;P&gt;I'm a SAS beginner and I need help with this question below.&amp;nbsp; a) shows error "&lt;SPAN&gt;Array subscript out of range at line 77 column 14" but I'm not sure how to correct it. b and c seem to have no problems but please correct me if I'm wrong. Thank you very much!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*2. What, if anything, is wrong with the following data step program fragments?&lt;/P&gt;&lt;PRE&gt;  a);
  data c;
   array x{20};
total=0;
do i=1 to 25 by 2;
   total=sum(x(i), total);
 end;
 
 

*b);
data d;
 array x{20};
    n=0;
    do i=1 to 25 by 2;
       n=n+1;
       total=sum(x(n), total);
     end;

 *c);
 do i=0.07 to 0.08;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Oct 2019 15:56:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-problem/m-p/596079#M171580</guid>
      <dc:creator>Amy0223</dc:creator>
      <dc:date>2019-10-13T15:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: array problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-problem/m-p/596082#M171583</link>
      <description>&lt;P&gt;For A and B the array is defined with 20 variables, but you are incrementing the index beyond 20.&lt;/P&gt;
&lt;P&gt;B works because you are using N and not I as the index into the array and N is increasing by 1 and not 2. So it will never get larger than 20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For A make the upper bound on the DO loop match the dimension of the Array. One way is to use the DIM() function in the DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 to dim(x) by 2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For C you did not specify the amount to increment by so it will use 1.&amp;nbsp; So the loop will run only once since 1.07 is greater than 0.08.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A more interesting problem with trying to do something like C is that decimal fractions are not represented exactly in floating point numbers.&amp;nbsp; So it might be better to control the loop using integers (like 7 to &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; and then divide the loop index by some factor (like 100) to make the fractional value you want to use in the loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Oct 2019 16:38:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-problem/m-p/596082#M171583</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-13T16:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: array problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-problem/m-p/596095#M171587</link>
      <description>Thank you so much for taking your precious time to answer my question. It's very helpful information. I really appreciate your kind help!</description>
      <pubDate>Sun, 13 Oct 2019 19:37:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-problem/m-p/596095#M171587</guid>
      <dc:creator>Amy0223</dc:creator>
      <dc:date>2019-10-13T19:37:27Z</dc:date>
    </item>
  </channel>
</rss>

