<?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: arrays for all rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/arrays-for-all-rows/m-p/511910#M137797</link>
    <description>Arrays run on all rows by default. Check your source data.</description>
    <pubDate>Sat, 10 Nov 2018 05:03:56 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-11-10T05:03:56Z</dc:date>
    <item>
      <title>arrays for all rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-for-all-rows/m-p/511907#M137795</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;This is the first time that I'm writing an array code by myself. Good news, it worked (YAY!). Bad news, it calculated only the first row. However I have 20 rows. Could you help to find what I'm missing. Also, I have only three variables named theta here, so it is easy to write&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;ex1_1 ex1_2 ex1_3 ex1_4 ex2_1 ex2_2 ex2_3 ex2_4 ex3_1 ex3_2 ex3_3 ex3_4 but when I have 500 thetas, is there an easy way to create variables as ex. The input files I used are attached and the code I used is below.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Many thanks&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;data par;&lt;BR /&gt;infile 'C:\cluster_new\mlg1.txt';&lt;BR /&gt;input a1 a2 a3 b1 b2 b3 ;&lt;BR /&gt;run;&lt;BR /&gt;data score;&lt;BR /&gt;infile 'C:\cluster_new\mlgs.txt';&lt;BR /&gt;input theta1 theta2 theta3;&lt;BR /&gt;run;&lt;BR /&gt;data all_pars;&lt;BR /&gt;merge par score;&lt;BR /&gt;run;&lt;BR /&gt;data all_pars;&lt;BR /&gt;set all_pars;&lt;BR /&gt;s1=-(a1+a2+a3)/4;&lt;BR /&gt;s2=s1+a1;&lt;BR /&gt;s3=s1+a2;&lt;BR /&gt;s4=s1+a3;&lt;BR /&gt;in1=-(b1+b2+b3)/4;&lt;BR /&gt;in2=in1+b1;&lt;BR /&gt;in3=in1+b2;&lt;BR /&gt;in4=in1+b3;&lt;BR /&gt;run;&lt;BR /&gt;data all_pars1;&lt;BR /&gt;set all_pars;&lt;BR /&gt;array t {*} theta1-theta3;&lt;BR /&gt;array ex {3,4} ex1_1 ex1_2 ex1_3 ex1_4 ex2_1 ex2_2 ex2_3 ex2_4 ex3_1 ex3_2 ex3_3 ex3_4;&lt;BR /&gt;array s {*} s1-s4;&lt;BR /&gt;array in {*} in1-in4;&lt;BR /&gt;do i=1 to 3;&lt;BR /&gt;do j=1 to 4;&lt;BR /&gt;ex(i,j)=exp(t(i)*s(j)+in(j));&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Nov 2018 04:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-for-all-rows/m-p/511907#M137795</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2018-11-10T04:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: arrays for all rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-for-all-rows/m-p/511910#M137797</link>
      <description>Arrays run on all rows by default. Check your source data.</description>
      <pubDate>Sat, 10 Nov 2018 05:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-for-all-rows/m-p/511910#M137797</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-10T05:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: arrays for all rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-for-all-rows/m-p/511973#M137824</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22174"&gt;@dustychair&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your mistake is in the (one-to-one)&amp;nbsp;MERGE step: The one-observation dataset SCORE contributes only missing values to observations no. 2, 3, etc. in this type of merge.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would correct it to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all_pars;
if _n_=1 then set score;
set par;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This reads the single observation from dataset SCORE only in the first iteration of the DATA step ("&lt;FONT face="courier new,courier"&gt;if _n_=1&lt;/FONT&gt;") and doesn't&amp;nbsp;touch these variables afterwards. Since all variables from a SET statement are automatically RETAINed, the theta values are copied to all subsequent observations, as desired.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding the (hypothetical) variable list ex1_1 ex1_2 ... ex500_4 (consisting of 2000 items):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You can define an array without specifying the individual variable names. For example, your definition&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array s {*} s1-s4;&lt;/CODE&gt;&lt;/PRE&gt;
is equivalent to&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array s{4};&lt;/CODE&gt;&lt;/PRE&gt;
because s1, s2, s3, s4 are the default variable names for this array.&lt;BR /&gt;&lt;BR /&gt;In the case of two- or higher-dimensional arrays the default names&amp;nbsp;use sequential numbers (as for one-dimensional arrays) in row-major order (see &lt;A href="https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=p08do6szetrxe2n136ush727sbuo.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;documentation&lt;/A&gt;). So, if you really need the dimension-specific indices (&lt;EM&gt;i&lt;/EM&gt;, &lt;EM&gt;j&lt;/EM&gt;, ...) &lt;EM&gt;in the variable names&lt;/EM&gt; rather than only in the array references (such as ex{&lt;EM&gt;i&lt;/EM&gt;,&lt;EM&gt;j&lt;/EM&gt;}), you still&amp;nbsp;need to specify the list of names.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;It's not difficult to create the long list mentioned above programmatically:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length c $16000; /* 500*4*(up to 8) characters: " ex123_4" */
do i=1 to 500;
  do j=1 to 4;
    c=catx(' ',c,cats('ex',i,'_',j));
  end;
end;
call symputx('vlist',c);
run;&lt;/CODE&gt;&lt;/PRE&gt;
The list is now available in macro variable VLIST and could be referenced in an ARRAY statement:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array ex{500,4} &amp;amp;vlist;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;However, depending on the purpose, a dataset with 2000+ variables might be unwieldy and it could make more sense to aim at a vertical (long) dataset structure.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Sat, 10 Nov 2018 22:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-for-all-rows/m-p/511973#M137824</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-11-10T22:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: arrays for all rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-for-all-rows/m-p/511988#M137839</link>
      <description>@FreelanceReinhard, you are awesome! Thank you for being patient with my simple questions and thank you for teaching me. I appreciate you!&lt;BR /&gt;Best,</description>
      <pubDate>Sun, 11 Nov 2018 05:38:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-for-all-rows/m-p/511988#M137839</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2018-11-11T05:38:11Z</dc:date>
    </item>
  </channel>
</rss>

