<?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 Distinguish between elements in a two-dimensional array. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Distinguish-between-elements-in-a-two-dimensional-array/m-p/24766#M4232</link>
    <description>If you declare &lt;BR /&gt;
&lt;BR /&gt;
array x(2,5); &lt;BR /&gt;
&lt;BR /&gt;
in a data step and assign values to the array, you get x1-x10 in the resulting table. The logical result would have been x11 to x15 and x21 to x25.&lt;BR /&gt;
&lt;BR /&gt;
By declaring &lt;BR /&gt;
&lt;BR /&gt;
array x(2,5) a1b1-a1b5 a2b1-a2b5; &lt;BR /&gt;
&lt;BR /&gt;
you can get what you want.&lt;BR /&gt;
&lt;BR /&gt;
But if it had been x(100,5)?&lt;BR /&gt;
&lt;BR /&gt;
By the way: Are expressions like&lt;BR /&gt;
&lt;BR /&gt;
array y(2,&amp;amp;n) r1c1-r1c&amp;amp;n r2c1-r2c&amp;amp;n;&lt;BR /&gt;
&lt;BR /&gt;
allowed?</description>
    <pubDate>Thu, 03 Dec 2009 07:27:38 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-12-03T07:27:38Z</dc:date>
    <item>
      <title>Distinguish between elements in a two-dimensional array.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinguish-between-elements-in-a-two-dimensional-array/m-p/24766#M4232</link>
      <description>If you declare &lt;BR /&gt;
&lt;BR /&gt;
array x(2,5); &lt;BR /&gt;
&lt;BR /&gt;
in a data step and assign values to the array, you get x1-x10 in the resulting table. The logical result would have been x11 to x15 and x21 to x25.&lt;BR /&gt;
&lt;BR /&gt;
By declaring &lt;BR /&gt;
&lt;BR /&gt;
array x(2,5) a1b1-a1b5 a2b1-a2b5; &lt;BR /&gt;
&lt;BR /&gt;
you can get what you want.&lt;BR /&gt;
&lt;BR /&gt;
But if it had been x(100,5)?&lt;BR /&gt;
&lt;BR /&gt;
By the way: Are expressions like&lt;BR /&gt;
&lt;BR /&gt;
array y(2,&amp;amp;n) r1c1-r1c&amp;amp;n r2c1-r2c&amp;amp;n;&lt;BR /&gt;
&lt;BR /&gt;
allowed?</description>
      <pubDate>Thu, 03 Dec 2009 07:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinguish-between-elements-in-a-two-dimensional-array/m-p/24766#M4232</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-03T07:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Distinguish between elements in a two-dimensional array.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinguish-between-elements-in-a-two-dimensional-array/m-p/24767#M4233</link>
      <description>Here is a simple example of creating a 2 dimensional array.&lt;BR /&gt;
&lt;BR /&gt;
%macro test;&lt;BR /&gt;
%let i = 20;&lt;BR /&gt;
%let j = 100;&lt;BR /&gt;
data one;&lt;BR /&gt;
array newv (&amp;amp;i, &amp;amp;j) %do k = 1 %to &amp;amp;i ; var_&amp;amp;k._1 - var_&amp;amp;k._&amp;amp;j %end; ;&lt;BR /&gt;
do m = 1 to &amp;amp;i;&lt;BR /&gt;
  do i = 1 to &amp;amp;j  ;&lt;BR /&gt;
    newv(m, i) = m*i;&lt;BR /&gt;
  end;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
%mend;&lt;BR /&gt;
%test;</description>
      <pubDate>Thu, 03 Dec 2009 13:12:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinguish-between-elements-in-a-two-dimensional-array/m-p/24767#M4233</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-12-03T13:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: Distinguish between elements in a two-dimensional array.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distinguish-between-elements-in-a-two-dimensional-array/m-p/24768#M4234</link>
      <description>Memory wise everything is stored contiguously, the two dimensions are just a pictorial view of the vector in a tabular form.&lt;BR /&gt;
&lt;BR /&gt;
Another way (beside the explicit association of named variables) would be to transform the two dimension address to a single one.&lt;BR /&gt;
&lt;BR /&gt;
[pre]d1,d2 = (d1-1)*max(d2)+d2[/pre]&lt;BR /&gt;
so, for a 2,5 vector, for example:&lt;BR /&gt;
&lt;BR /&gt;
1,2 becomes (1-1)*5+2=2, thus X2&lt;BR /&gt;
1,5 becomes (1-1)*5+5=5, thus X5&lt;BR /&gt;
2,3 becomes (2-1)*5+3=8, thus X8&lt;BR /&gt;
2,5 becomes (2-1)*5+5=10, thus X10&lt;BR /&gt;
&lt;BR /&gt;
you could code this into a macro like this:&lt;BR /&gt;
&lt;BR /&gt;
[pre]%macro i(D1,D2,MAX_D2);&lt;BR /&gt;
%sysevalf( (&amp;amp;D1-1)*&amp;amp;MAX_D2+&amp;amp;D2)&lt;BR /&gt;
%mend i;[/pre]&lt;BR /&gt;
then you just have to reference each variable using the macro, this way:&lt;BR /&gt;
&lt;BR /&gt;
[pre]X%i(1,2,5)=10000; * which resolves to X2;&lt;BR /&gt;
X%i(1,5,5)=10001; * which resolves to X5;&lt;BR /&gt;
X%i(2,3,5)=10002; * which resolves to X8;&lt;BR /&gt;
X%i(2,5,5)=10003; * which resolves to X10;[/pre]&lt;BR /&gt;
Cheers from Portugal&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Thu, 03 Dec 2009 17:30:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distinguish-between-elements-in-a-two-dimensional-array/m-p/24768#M4234</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-12-03T17:30:45Z</dc:date>
    </item>
  </channel>
</rss>

