<?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: trying to add values to an array through looping without replacing the old values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/trying-to-add-values-to-an-array-through-looping-without/m-p/426573#M281329</link>
    <description>&lt;P&gt;Each array has a fixed number of elements.&amp;nbsp; In that sense, it is not something you can expand or add to.&amp;nbsp; All you can do is replace some of the current values within the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There may be a way to accomplish what you need, but you will have to illustrate the "before" and "after" picture using a couple of observations of data.&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jan 2018 18:19:19 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-01-10T18:19:19Z</dc:date>
    <item>
      <title>trying to add values to an array through looping without replacing the old values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/trying-to-add-values-to-an-array-through-looping-without/m-p/426565#M281328</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a new SAS user, so thanks in advance for your help. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a loop inside a loop that puts&amp;nbsp;x variable values into an array, and then the outer loop iterates y times. When it iterates the next y time, I want the array to keep the previous values and add the new values to that array instead of replacing the previous values (I assume that if I use retain, it would stop it from replacing but&amp;nbsp;not add the new ones). This is my basic code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; &amp;nbsp;do y = 1 to 5;&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp; &amp;nbsp;if array1[y] ~= . then&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; do x = 1 to 3;&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp; if array2[x] = . or array2[x] &amp;lt; array1[y] then array3[x] = .;&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; else array3[x] = array2[x] - array1[y];&lt;/P&gt;&lt;P&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; else do x = 1 to 3;&lt;/P&gt;&lt;P&gt;8&amp;nbsp;&amp;nbsp;&amp;nbsp; array3[x] = .;&lt;/P&gt;&lt;P&gt;9&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;10&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried adding this before the last end statement (so it is included in the y iteration):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Z = 1; (specified outside of loops)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;11&amp;nbsp;&amp;nbsp; do&amp;nbsp;j = 1 to 3;&lt;/P&gt;&lt;P&gt;12&amp;nbsp;&amp;nbsp; array4[Z] = array3[j];&lt;/P&gt;&lt;P&gt;13&amp;nbsp;&amp;nbsp; Z+1;&lt;/P&gt;&lt;P&gt;14&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;15&amp;nbsp;&amp;nbsp; Z+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...but it says there's an array subscript out of range at line 12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've attached the actual code I used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ideas???&lt;/P&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>Wed, 10 Jan 2018 17:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/trying-to-add-values-to-an-array-through-looping-without/m-p/426565#M281328</guid>
      <dc:creator>matte109</dc:creator>
      <dc:date>2018-01-10T17:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: trying to add values to an array through looping without replacing the old values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/trying-to-add-values-to-an-array-through-looping-without/m-p/426573#M281329</link>
      <description>&lt;P&gt;Each array has a fixed number of elements.&amp;nbsp; In that sense, it is not something you can expand or add to.&amp;nbsp; All you can do is replace some of the current values within the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There may be a way to accomplish what you need, but you will have to illustrate the "before" and "after" picture using a couple of observations of data.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2018 18:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/trying-to-add-values-to-an-array-through-looping-without/m-p/426573#M281329</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-10T18:19:19Z</dc:date>
    </item>
  </channel>
</rss>

