<?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 only Producing 2 Observations instead of 12 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/508930#M136735</link>
    <description>What does DIM return when you have a two dimensional array? The first or second dimension? Since it's two I'm going to guess the first. Look up how to find the other dimensions in the docs &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;</description>
    <pubDate>Tue, 30 Oct 2018 20:38:47 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-10-30T20:38:47Z</dc:date>
    <item>
      <title>Array only Producing 2 Observations instead of 12</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/508918#M136725</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been working with this data set and finally got an Array to work, but I wanted to change it to include both pre and post data. As such, I modified my code from:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Tall;
	set infl.arc_inflation_jb_102618;
	array _month(12) N_PreResYr1stM_House
		N_PreResYr2ndM_House
		N_PreResYr3rdM_House
		N_PreResYr4thM_House
		N_PreResYr5thM_House
		N_PreResYr6thM_House
		N_PreResYr7thM_House
		N_PreResYr8thM_House
		N_PreResYr9thM_House
		N_PreResYr10thM_House
		N_PreResYr11thM_House
		N_PreResYr12thM_House;


	do i=1 to dim(_month);
		interval='Month';
		Month = i;
			PreResYr_House = _month(i);	
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This code was working fine at giving me the 12 months split up.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Tall;
	set infl.arc_inflation_jb_102618;
	array _month(2,12) N_PreResYr1stM_House
		N_PreResYr2ndM_House
		N_PreResYr3rdM_House
		N_PreResYr4thM_House
		N_PreResYr5thM_House
		N_PreResYr6thM_House
		N_PreResYr7thM_House
		N_PreResYr8thM_House
		N_PreResYr9thM_House
		N_PreResYr10thM_House
		N_PreResYr11thM_House
		N_PreResYr12thM_House
	N_PostResYr1stM_House
		N_PostResYr2ndM_House
		N_PostResYr3rdM_House
		N_PostResYr4thM_House
		N_PostResYr5thM_House
		N_PostResYr6thM_House
		N_PostResYr7thM_House
		N_PostResYr8thM_House
		N_PostResYr9thM_House
		N_PostResYr10thM_House
		N_PostResYr11thM_House
		N_PostResYr12thM_House;

	do i=1 to dim(_month);
		interval='Month';
		Month = i;
			PreResYr_House = _month(1,i);
PostResYr_House = _month(2,i);	
		output;
	end;
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Now I cannot figure out why this is not giving me my 12 months still with both pre and post but is producing only 2 rows with the correct values for just months 1 and 2?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 20:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/508918#M136725</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2018-10-30T20:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Array only Producing 2 Observations instead of 12</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/508930#M136735</link>
      <description>What does DIM return when you have a two dimensional array? The first or second dimension? Since it's two I'm going to guess the first. Look up how to find the other dimensions in the docs &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;</description>
      <pubDate>Tue, 30 Oct 2018 20:38:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/508930#M136735</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-30T20:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: Array only Producing 2 Observations instead of 12</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/508934#M136737</link>
      <description>&lt;P&gt;use&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;do i&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to &lt;SPAN class="token function"&gt;dim2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;_month&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And still&lt;/P&gt;
&lt;P&gt;this piece of logic seems incorrect to me&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;PreResYr_House &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; _month&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
PostResYr_House &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; _month&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;as you are merely overwriting&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to do&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;do i&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to &lt;SPAN class="token function"&gt;dim&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;_month&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
		interval&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'Month'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
		&lt;SPAN class="token function"&gt;Month&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; i&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
			PreResYr_House &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; _month&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;output;
PostResYr_House &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; _month&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;	
		output&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	end&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Oct 2018 20:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/508934#M136737</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-30T20:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Array only Producing 2 Observations instead of 12</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/508940#M136741</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; I think other than dim2 the code is likely what the OP wants, since it will create pre/post beside each other which makes it easier to calculate differences. For a full 'tidy' data set though it should be the way you've suggested.</description>
      <pubDate>Tue, 30 Oct 2018 21:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/508940#M136741</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-30T21:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: Array only Producing 2 Observations instead of 12</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/508941#M136742</link>
      <description>&lt;P&gt;True at 4 pm and I am already tired. Will have to wait for OP to give us a sample of what he/she has and the requirement&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 21:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/508941#M136742</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-30T21:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Array only Producing 2 Observations instead of 12</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/508968#M136753</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241893"&gt;@joebacon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have been working with this data set and finally got an Array to work, but I wanted to change it to include both pre and post data. As such, I modified my code from:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Tall;
	set infl.arc_inflation_jb_102618;
	array _month(12) N_PreResYr1stM_House
		N_PreResYr2ndM_House
		N_PreResYr3rdM_House
		N_PreResYr4thM_House
		N_PreResYr5thM_House
		N_PreResYr6thM_House
		N_PreResYr7thM_House
		N_PreResYr8thM_House
		N_PreResYr9thM_House
		N_PreResYr10thM_House
		N_PreResYr11thM_House
		N_PreResYr12thM_House;


	do i=1 to dim(_month);
		interval='Month';
		Month = i;
			PreResYr_House = _month(i);	
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code was working fine at giving me the 12 months split up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to this:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Tall;
	set infl.arc_inflation_jb_102618;
	array _month(2,12) N_PreResYr1stM_House
		N_PreResYr2ndM_House
		N_PreResYr3rdM_House
		N_PreResYr4thM_House
		N_PreResYr5thM_House
		N_PreResYr6thM_House
		N_PreResYr7thM_House
		N_PreResYr8thM_House
		N_PreResYr9thM_House
		N_PreResYr10thM_House
		N_PreResYr11thM_House
		N_PreResYr12thM_House
	N_PostResYr1stM_House
		N_PostResYr2ndM_House
		N_PostResYr3rdM_House
		N_PostResYr4thM_House
		N_PostResYr5thM_House
		N_PostResYr6thM_House
		N_PostResYr7thM_House
		N_PostResYr8thM_House
		N_PostResYr9thM_House
		N_PostResYr10thM_House
		N_PostResYr11thM_House
		N_PostResYr12thM_House;

	do i=1 to dim(_month);
		interval='Month';
		Month = i;
			PreResYr_House = _month(1,i);
PostResYr_House = _month(2,i);	
		output;
	end;
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Now I cannot figure out why this is not giving me my 12 months still with both pre and post but is producing only 2 rows with the correct values for just months 1 and 2?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;From the first post I and following I was thinking that doing one array per topic would be the way the go. then you have parallel code and copy&amp;nbsp; paste and edit actual gets moderately easy. You have also discovered whey SAS programmers tend to place iterated values at the end of a variable name and not in the middle. Arrays are much easy to work with when you have N_PreResYrM_House1 to N_PreResYrM_House12 as the array statement would be : array a N_PreResYrM_House1&amp;nbsp;- N_PreResYrM_House12&amp;nbsp;;&lt;/P&gt;
&lt;P&gt;Personally I would rename your variables just to make the arrays simpler. I think if you search the forum you may find an example of PROC DATASETS used to do so with indexed variables.&lt;/P&gt;
&lt;P&gt;1st , 2nd, 3rd , 4th do not belong in naming schemes either. Use&amp;nbsp;1 2 3 4 (except for the start of the name).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider&lt;/P&gt;
&lt;PRE&gt;data example;
   set imaginarydata;
   array h var1_house var2_house var3_house;
   array c var1_car   var2_car   var3_car  ;
   array b var1_boat  var2_boat  var3_boat ;
   do month=1 to dim(h);
      house = h[month];
      car   = c[month];
      boat  = b[month];
      output;
   end;
   drop var: ;
run;&lt;/PRE&gt;
&lt;P&gt;Pick short names for arrays as practical. If your groups of variables only vary by a few characters such as your PRERES vs POSTRES&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;get one of these arrays setup and you can copy and select and replace in selection in the editor to make the 2nd (3rd 4th etc) similar arrays.&lt;/P&gt;
&lt;P&gt;Then the code inside loop for the different topics is copy and paste similarly.&lt;/P&gt;
&lt;P&gt;While SAS does support multiple dimension arrays I doubt if the complexity is warranted here.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 22:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/508968#M136753</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-30T22:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: Array only Producing 2 Observations instead of 12</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/509123#M136825</link>
      <description>&lt;P&gt;Thank you! Obviously I am very new and trying to learn. This helped break it down. I appreciate it.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Oct 2018 14:30:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/509123#M136825</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2018-10-31T14:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: Array only Producing 2 Observations instead of 12</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/509125#M136826</link>
      <description>&lt;P&gt;The first bit of code was what i needed and then I reorganized it in a really long, terrible way. However, when i got the second bit of code, it helped me learn some more about how SAS processes. Thanks for that. Cool little trick to put them side by side like Reeza said.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 31 Oct 2018 14:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/509125#M136826</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2018-10-31T14:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Array only Producing 2 Observations instead of 12</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/509126#M136827</link>
      <description>&lt;P&gt;Thank you for always being patient and helping me learn! You're seriously the best.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Oct 2018 14:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/509126#M136827</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2018-10-31T14:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Array only Producing 2 Observations instead of 12</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/509129#M136829</link>
      <description>&lt;P&gt;We are glad. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Have a good day!&lt;/P&gt;</description>
      <pubDate>Wed, 31 Oct 2018 14:32:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-only-Producing-2-Observations-instead-of-12/m-p/509129#M136829</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-31T14:32:18Z</dc:date>
    </item>
  </channel>
</rss>

