<?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: How to deal with Array subscript issue? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-deal-with-Array-subscript-issue/m-p/581160#M165143</link>
    <description>&lt;P&gt;You can reference an array element with a variable. You can not define an array with a variable. You either explicitly state a size or if using a list of variables do not define a size but let the number of elements in the list define the size.&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;
&lt;P&gt;Post log and code entries into code windows opened on the forum with the {I} or "running man" icons to preserve formatting.&lt;/P&gt;
&lt;P&gt;The error is fairly clear:&lt;/P&gt;
&lt;PRE&gt;365  data work.test1;
366       set work.test;
367           array test{c} a-- c;
                         -
                         22
                         202
ERROR: Too many variables defined for the dimension(s) specified for the array test.
ERROR 22-322: Syntax error, expecting one of the following: an integer constant, *.

ERROR 202-322: The option or parameter is not recognized and will be ignored.

368  run;
&lt;/PRE&gt;
&lt;P&gt;The underlined C and error 322 is telling that you need either an actual integer, i.e.3 or *&lt;/P&gt;
&lt;P&gt;the Code should be&lt;/P&gt;
&lt;PRE&gt;data work.test1;
     set work.test;
     array test{*} a-- c;
run;&lt;/PRE&gt;
&lt;P&gt;Using a VARIABLE integer to &lt;U&gt;reference&lt;/U&gt; elements of an array:&lt;/P&gt;
&lt;PRE&gt;data work.test1;
     set work.test;
     array test{*} a-- c;
     do i = 1 to dim(test);
      x= test[i];
      put _n_= I= x=;
    end;
run;&lt;/PRE&gt;
&lt;P&gt;The variable I takes on values of 1 , 2 and 3. _n_ is an automatic variable that indicates, in this case, which record has been read from the input set.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Aug 2019 14:52:40 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-08-14T14:52:40Z</dc:date>
    <item>
      <title>How to deal with Array subscript issue?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-deal-with-Array-subscript-issue/m-p/581113#M165131</link>
      <description>&lt;P&gt;Hi Everybody.&lt;BR /&gt;&lt;BR /&gt;I have some confusing situation regarding SAS Arrays.&lt;BR /&gt;The question is following.&lt;BR /&gt;&lt;BR /&gt;Syntax -&amp;gt;&amp;nbsp;&amp;nbsp;&lt;FONT face="arial black,avant garde"&gt;array array-name {n} &amp;lt;$&amp;gt; array-elements &amp;lt;(initial-values)&amp;gt;;&lt;BR /&gt;&lt;/FONT&gt;&lt;BR /&gt;In the multiple SAS guides and topics about arrays, the definition of {n} is following `&lt;BR /&gt;" N is the array subscript in the array definition and it refers to the number of elements within the array. A numeric&lt;BR /&gt;constant, &lt;STRONG&gt;&lt;U&gt;a variable whose value is a number, a numeric SAS expression&lt;/U&gt;&lt;/STRONG&gt;, or an asterisk (*) may be used as the&lt;BR /&gt;subscript. "&lt;BR /&gt;&lt;BR /&gt;Yes, the confusing is the underlined part.&lt;BR /&gt;I have tried that part in practice.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input a b c;
	c=3;
	    cards;
		1 2 3
		4 5 6
		7 8 9
	    ;
run;

data test1;
     set test;
         array test{c} a-- c; /*Assuming the part where says "a variable whose value is a number*/
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;After running following program, the log look like this`&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;---------------------------------------LOG------------------------------------------------&lt;BR /&gt;&amp;nbsp;array test{c} a-- c;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 22&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202&lt;BR /&gt;ERROR: Too many variables defined for the dimension(s) specified for the array test.&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: an integer constant, *.&lt;BR /&gt;ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;------------------------------------------------------------------------------------------&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;And for second part, which assume "a numeric SAS expression", I have no ideas what it could be, 1+1+1 a new variable which created with a numeric expression?&lt;BR /&gt;Could you please help me on this, maybe I'm doing something wrong?&lt;BR /&gt;Thank you in advance.&lt;/CODE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 14:40:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-deal-with-Array-subscript-issue/m-p/581113#M165131</guid>
      <dc:creator>webart999ARM</dc:creator>
      <dc:date>2019-08-14T14:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to deal with Array subscript issue?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-deal-with-Array-subscript-issue/m-p/581160#M165143</link>
      <description>&lt;P&gt;You can reference an array element with a variable. You can not define an array with a variable. You either explicitly state a size or if using a list of variables do not define a size but let the number of elements in the list define the size.&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;
&lt;P&gt;Post log and code entries into code windows opened on the forum with the {I} or "running man" icons to preserve formatting.&lt;/P&gt;
&lt;P&gt;The error is fairly clear:&lt;/P&gt;
&lt;PRE&gt;365  data work.test1;
366       set work.test;
367           array test{c} a-- c;
                         -
                         22
                         202
ERROR: Too many variables defined for the dimension(s) specified for the array test.
ERROR 22-322: Syntax error, expecting one of the following: an integer constant, *.

ERROR 202-322: The option or parameter is not recognized and will be ignored.

368  run;
&lt;/PRE&gt;
&lt;P&gt;The underlined C and error 322 is telling that you need either an actual integer, i.e.3 or *&lt;/P&gt;
&lt;P&gt;the Code should be&lt;/P&gt;
&lt;PRE&gt;data work.test1;
     set work.test;
     array test{*} a-- c;
run;&lt;/PRE&gt;
&lt;P&gt;Using a VARIABLE integer to &lt;U&gt;reference&lt;/U&gt; elements of an array:&lt;/P&gt;
&lt;PRE&gt;data work.test1;
     set work.test;
     array test{*} a-- c;
     do i = 1 to dim(test);
      x= test[i];
      put _n_= I= x=;
    end;
run;&lt;/PRE&gt;
&lt;P&gt;The variable I takes on values of 1 , 2 and 3. _n_ is an automatic variable that indicates, in this case, which record has been read from the input set.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 14:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-deal-with-Array-subscript-issue/m-p/581160#M165143</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-14T14:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to deal with Array subscript issue?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-deal-with-Array-subscript-issue/m-p/581187#M165156</link>
      <description>&lt;P&gt;There are two types of Arrays in SAS. One is Named Array and the other is Nameless Array. The former deals with SAS variable-names as a shortcut to represent individual variables. The latter is called _Temporary_ Array. The _temporary_ arrays require the dimension (size) of the array at Compilation phase of a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your example mixed both the usages. For instance,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data test1;
     set test;
         array test{c} a-- c; /*Assuming the part where says "the variable whose value is a number*/
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are saying that array TEST has the dimension of C where C comes as part of the data set TEST. The value of C (your 3) is not available at the compilation phase of the Data Step (Data Test1). It needs a constant value as 3. See the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data test1;
     set test;
         array test{3} a-- c; /*Assuming the part where says "the variable whose value is a number*/
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This works happily - no errors.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In case of Named array, a better way to declare an array is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data aa;
   set test;
   array test[*] a -- c;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here the STAR takes care of the size of the array. Even a better way will be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data aa;
   set test;
   array test a -- c;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The size of the array is implicitly computed at the time of compilation phase.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 15:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-deal-with-Array-subscript-issue/m-p/581187#M165156</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-08-14T15:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to deal with Array subscript issue?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-deal-with-Array-subscript-issue/m-p/581248#M165180</link>
      <description>&lt;P&gt;You are confusing array declaration and array reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Array declaration is where you define the array, it is processed during datastep compilation, before any execution. At that point SAS needs to know how many elements your array will have. For example,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array a{10};&lt;/P&gt;
&lt;P&gt;array a a1-a10;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;are valid and equivalent array declarations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Array reference occurs during datastep execution. At that point you tell SAS which element of the array is referred by your expression with an index value. The index value must resolve to a number. For example, following the declaration above,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i = 10;&lt;/P&gt;
&lt;P&gt;a{i} = a1 + a{5+5};&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;adds the value of the first array element to the tenth array element.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 19:01:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-deal-with-Array-subscript-issue/m-p/581248#M165180</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-08-14T19:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to deal with Array subscript issue?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-deal-with-Array-subscript-issue/m-p/581348#M165222</link>
      <description>&lt;P&gt;Thank you all for your answers.&lt;BR /&gt;&lt;BR /&gt;As in the last answer said, "&lt;SPAN&gt;I confused array declaration and array reference".&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Aug 2019 05:16:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-deal-with-Array-subscript-issue/m-p/581348#M165222</guid>
      <dc:creator>webart999ARM</dc:creator>
      <dc:date>2019-08-15T05:16:20Z</dc:date>
    </item>
  </channel>
</rss>

