<?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: reading values into array starting at index 0 instead of 1 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239121#M43959</link>
    <description>&lt;P&gt;Why do you need an array which starts at 0? &amp;nbsp;The array strcuture is specifically designed for array[1-n]. &amp;nbsp;What your effectively saying is that you want a zero element which doesn't make sense, even behind the scenes if you force SAS to use zero it will internally create 1-n and have a pointer. &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 14 Dec 2015 11:19:54 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-12-14T11:19:54Z</dc:date>
    <item>
      <title>reading values into array starting at index 0 instead of 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239056#M43944</link>
      <description>&lt;P&gt;I'm having problems reading macro variables into an array that starts at index 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a much simplified example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a0=0; %let a1=1; %let a2=2; %let a3=3;
data test (keep= a_0-a_3);
	array a_(0:3) (&amp;amp;a0 &amp;amp;a1 &amp;amp;a2 &amp;amp;a3);
	output test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run this code I receive the following error message in the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WARNING: Not all variables in the list a_0-a_3 were found.
NOTE: The data set WORK.TEST has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and the values in the test dataset have been offset and are incomplete:&lt;/P&gt;
&lt;P&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp; a_1&amp;nbsp;&amp;nbsp;&amp;nbsp; a_2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a_3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know SAS can handle arrays with indexes beginning at 0 rather than 1. What am I doing wrong here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks! in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Robert&lt;/P&gt;</description>
      <pubDate>Sun, 13 Dec 2015 16:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239056#M43944</guid>
      <dc:creator>RobF</dc:creator>
      <dc:date>2015-12-13T16:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: reading values into array starting at index 0 instead of 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239058#M43945</link>
      <description>&lt;P&gt;Although SAS array index could start from 0, array variable of elements should be count form 1, result should be a1-a4, but you keep a0-a3, not include a4, keep a0 which does not exist.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Dec 2015 17:52:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239058#M43945</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2015-12-13T17:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: reading values into array starting at index 0 instead of 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239063#M43946</link>
      <description>If you want to rename variables you may need to explicitly list the variable names unfortunately.&lt;BR /&gt;&lt;BR /&gt;array a_(0:3) a_0-a_3 (&amp;amp;a0 &amp;amp;a1 &amp;amp;a2 &amp;amp;a3);</description>
      <pubDate>Sun, 13 Dec 2015 18:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239063#M43946</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-13T18:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: reading values into array starting at index 0 instead of 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239067#M43947</link>
      <description>&lt;P&gt;An unfortunate &lt;EM&gt;feature&lt;/EM&gt; of SAS datastep arrays, indeed!&lt;/P&gt;</description>
      <pubDate>Sun, 13 Dec 2015 20:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239067#M43947</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-12-13T20:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: reading values into array starting at index 0 instead of 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239068#M43948</link>
      <description>&lt;P&gt;Thanks Reeza!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had a feeling there was a simple solution I'd overlooked.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Dec 2015 20:38:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239068#M43948</guid>
      <dc:creator>RobF</dc:creator>
      <dc:date>2015-12-13T20:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: reading values into array starting at index 0 instead of 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239121#M43959</link>
      <description>&lt;P&gt;Why do you need an array which starts at 0? &amp;nbsp;The array strcuture is specifically designed for array[1-n]. &amp;nbsp;What your effectively saying is that you want a zero element which doesn't make sense, even behind the scenes if you force SAS to use zero it will internally create 1-n and have a pointer. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2015 11:19:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239121#M43959</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-14T11:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: reading values into array starting at index 0 instead of 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239160#M43964</link>
      <description>&lt;P&gt;Right, normally I'm happy with the array index starting at 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case I'm refining a program that iteratively calculates regression coefficients p0, p1, p2, ..., p&amp;amp;numvar, and for convenience's sake I'd like the coefficient array to start at 0 (the intercept). One less thing to keep track of in my code if I don't have to subtract one from the array index when I'm printing out the final array values.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2015 15:01:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239160#M43964</guid>
      <dc:creator>RobF</dc:creator>
      <dc:date>2015-12-14T15:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: reading values into array starting at index 0 instead of 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239167#M43966</link>
      <description>&lt;P&gt;Yes, but then you are mixing up the forumla logic with the underlying code program. p0 is still the first element in the array, whatever you call it. &amp;nbsp;Personally I would normalise the data, i.e. have a row for each result - thats CDISC model structure, and transpose only when needed for outputs. &amp;nbsp;However if you fixed on arrays, then maybe a two dimensional array would work:&lt;/P&gt;
&lt;PRE&gt;data want;
  array p_results{4,2} (0,0.1234,
                        1,0.34567,
                        2,0.8765,
                        3,0.2309); 
  do i=1 to 4;
    put "P=" p_results{i,1}  "Result=" p_results{i,2};
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Dec 2015 15:28:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239167#M43966</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-14T15:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: reading values into array starting at index 0 instead of 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239212#M43971</link>
      <description>&lt;P&gt;Thanks RW9, that's an interesting solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code (which performs a lasso/ridge regression)&amp;nbsp;reads the analysis dataset into an array &amp;amp; processes the data in a data _null_ data step&amp;nbsp;to save processing time. Getting it to work was a minor miracle, but there are still a few bugs in my array code &amp;amp; I'm open to suggestions.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2015 18:09:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239212#M43971</guid>
      <dc:creator>RobF</dc:creator>
      <dc:date>2015-12-14T18:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: reading values into array starting at index 0 instead of 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239300#M44003</link>
      <description>&lt;P&gt;Well, I am not familiar with the regression, however I would point out that almost all functions work with by grouping, i.e. having some variables as ids and then some as values to be analysed. &amp;nbsp;E.g:&lt;/P&gt;
&lt;P&gt;proc means data=have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; class&amp;nbsp;group1 group2;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This type of processing will be the fastest (I assume) as the grouping is done within the compiled function rather than interpreted from your code. &amp;nbsp;Maybe if you post a sample + some test data could give an example.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2015 09:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reading-values-into-array-starting-at-index-0-instead-of-1/m-p/239300#M44003</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-15T09:02:59Z</dc:date>
    </item>
  </channel>
</rss>

