<?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 subscript out of range: processing previous column in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Array-subscript-out-of-range-processing-previous-column/m-p/310363#M61280</link>
    <description>&lt;P&gt;It looks like your reading an Excel file, are you sure all the variables are present and you counted them correctly? &amp;nbsp;You will find coding would be far simpler if you normalised the data, i.e. have weeks going down rather than across, this question for instance disappears as you can use aggregates or procedures on the data.&lt;/P&gt;
&lt;P&gt;As for your question:&lt;/P&gt;
&lt;PRE&gt;Array Week {53} week0-week52;
Array PCarUnl {52} PCarUnl1 - PCarUnl52;
 
 
do I=1 to 52;
        lastWeek=I-1;
        PCarUnl{i} = Week{i} - Week{lastWeek};&lt;/PRE&gt;
&lt;P&gt;Now you create an array called week, with 53 elements = week{1}-week{53}. &amp;nbsp;Now in your loop, you start I at 1, and lastweek becomes 0, now week{0} is not within the 1-53 elements so its out of bounds. &amp;nbsp;Its probably that you want to do i=2-53, then the first iteration would be 2-1 for lastweek.&lt;/P&gt;</description>
    <pubDate>Wed, 09 Nov 2016 13:28:41 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-11-09T13:28:41Z</dc:date>
    <item>
      <title>Array subscript out of range: processing previous column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Array-subscript-out-of-range-processing-previous-column/m-p/310358#M61279</link>
      <description>&lt;P&gt;Hi I am having a problem with processing an array but I just can't seem to get it using a simple loop. Essentially I am trying to get a week weekly count from cumulative value given for week. So for example the weekly value for week #10 I want would be Week #10 - Week#9. Using the Macro processor there is no problem with the loop however with a the do loop in the data step I get an "array subscript out of range" error.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;FONT face="Courier New" size="2" color="navy"&gt;&lt;SPAN&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;FONT color="black"&gt; producer_shipments13; &lt;/FONT&gt;&lt;FONT color="blue"&gt;set&lt;/FONT&gt;&lt;FONT color="black"&gt; pcars13."Sheet1$"n;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="Courier New" size="2" color="blue"&gt;&lt;SPAN&gt;Array&lt;FONT color="black"&gt; Week {&lt;/FONT&gt;&lt;FONT color="teal"&gt;&lt;STRONG&gt;53&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="black"&gt;} week0-week52;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="Courier New" size="2" color="blue"&gt;&lt;SPAN&gt;Array&lt;FONT color="black"&gt; PCarUnl {&lt;/FONT&gt;&lt;FONT color="teal"&gt;&lt;STRONG&gt;52&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="black"&gt;} PCarUnl1 - PCarUnl52;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="Courier New" size="2" color="blue"&gt;&lt;SPAN&gt;do&lt;FONT color="black"&gt; I=&lt;/FONT&gt;&lt;FONT color="teal"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt; to &lt;FONT color="teal"&gt;&lt;STRONG&gt;52&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="black"&gt;;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lastWeek=I-&lt;FONT color="teal"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PCarUnl{i} = Week{i} - Week{lastWeek};&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="Courier New" size="2" color="blue"&gt;&lt;SPAN&gt;end&lt;FONT color="black"&gt;;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="Courier New" size="2" color="navy"&gt;&lt;SPAN&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;FONT color="black"&gt;;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would appear that the error is occuring at start of the loop and if I change my loop to start at 2, and make my PCarUnl array 1 column larger I get what I need with a couple of null columns to clean up.&lt;/P&gt;
&lt;DIV&gt;&lt;FONT color="navy"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;FONT color="black"&gt; producer_shipments13; &lt;/FONT&gt;&lt;FONT color="blue"&gt;set&lt;/FONT&gt;&lt;FONT color="black"&gt; pcars13."Sheet1$"n;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color="blue"&gt;Array&lt;FONT color="black"&gt; Week {&lt;/FONT&gt;&lt;FONT color="teal"&gt;&lt;STRONG&gt;53&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="black"&gt;} week0-week52;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color="blue"&gt;Array&lt;STRONG&gt;&lt;FONT color="black"&gt; PCarUnl &lt;FONT color="#FF0000"&gt;{&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#FF0000"&gt;53&lt;/FONT&gt;&lt;FONT color="black"&gt;&lt;FONT color="#FF0000"&gt;} PCarUnl0&lt;/FONT&gt; - PCarUnl52;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face="Calibri" size="2"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color="blue"&gt;do&lt;FONT color="black"&gt; I=&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="blue"&gt; to &lt;FONT color="teal"&gt;&lt;STRONG&gt;52&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="black"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lastWeek=I-&lt;FONT color="teal"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt;;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PCarUnl{i} = Week{i} - Week{lastWeek};&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color="blue"&gt;end&lt;FONT color="black"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color="navy"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;FONT color="black"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would have assumed this is a Program Data Vector thing for row prcessing but not so confident on how things work in arrays. Any array mavens out there who care explain or have a link that I can read through on what is happening.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kevin&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2016 13:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Array-subscript-out-of-range-processing-previous-column/m-p/310358#M61279</guid>
      <dc:creator>SUDOKU</dc:creator>
      <dc:date>2016-11-09T13:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Array subscript out of range: processing previous column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Array-subscript-out-of-range-processing-previous-column/m-p/310363#M61280</link>
      <description>&lt;P&gt;It looks like your reading an Excel file, are you sure all the variables are present and you counted them correctly? &amp;nbsp;You will find coding would be far simpler if you normalised the data, i.e. have weeks going down rather than across, this question for instance disappears as you can use aggregates or procedures on the data.&lt;/P&gt;
&lt;P&gt;As for your question:&lt;/P&gt;
&lt;PRE&gt;Array Week {53} week0-week52;
Array PCarUnl {52} PCarUnl1 - PCarUnl52;
 
 
do I=1 to 52;
        lastWeek=I-1;
        PCarUnl{i} = Week{i} - Week{lastWeek};&lt;/PRE&gt;
&lt;P&gt;Now you create an array called week, with 53 elements = week{1}-week{53}. &amp;nbsp;Now in your loop, you start I at 1, and lastweek becomes 0, now week{0} is not within the 1-53 elements so its out of bounds. &amp;nbsp;Its probably that you want to do i=2-53, then the first iteration would be 2-1 for lastweek.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2016 13:28:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Array-subscript-out-of-range-processing-previous-column/m-p/310363#M61280</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-09T13:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: Array subscript out of range: processing previous column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Array-subscript-out-of-range-processing-previous-column/m-p/310377#M61281</link>
      <description>&lt;P&gt;Thanks RW9, yes the data are in excel and i could have normalised from excel using a proc transpose in SAS but I'm not in control of the design of the excel sheets. However,&amp;nbsp;I am very confident the variables are correct and I am not missing columns in the array. FWIW the data were&amp;nbsp;keyed into the tables by our regional staff for many years now from manual reports that are created and posted to industry. We have a data warehouse and are looking to move reporting from it but there are questions from executives and industry as to whether the reports will be different. And so it's my job to use both sources and compare.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Indeed I did need to extend the loop to 53 to get week 52 included and I think I understand what I need to code to get the information.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks Again,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kevin&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2016 14:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Array-subscript-out-of-range-processing-previous-column/m-p/310377#M61281</guid>
      <dc:creator>SUDOKU</dc:creator>
      <dc:date>2016-11-09T14:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Array subscript out of range: processing previous column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Array-subscript-out-of-range-processing-previous-column/m-p/310387#M61282</link>
      <description>&lt;P&gt;If you want to index your array from 0 to 52 rather than 1 to 53&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array first_array(0:52) week0-week52;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2016 14:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Array-subscript-out-of-range-processing-previous-column/m-p/310387#M61282</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-09T14:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Array subscript out of range: processing previous column</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Array-subscript-out-of-range-processing-previous-column/m-p/310433#M61283</link>
      <description>&lt;P&gt;To avoid proliferation of uneeded variables you might try instead of&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size="2"&gt;lastWeek=I-&lt;/FONT&gt;&lt;FONT color="teal" size="2"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR /&gt;PCarUnl{i} = Week{i} - Week{lastWeek};&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PCarUnl{i} = Week{i} - Week{i-1};&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While potentially confusing, you can put functions in the index position. Pretty much anything that resolves to an integer in the subscript range is valid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2016 16:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Array-subscript-out-of-range-processing-previous-column/m-p/310433#M61283</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-09T16:08:11Z</dc:date>
    </item>
  </channel>
</rss>

