<?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: Passing a Period through an array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Period-through-an-array/m-p/309760#M66745</link>
    <description>&lt;P&gt;The first issue&amp;nbsp;is it becomes very easy to generate an error of array out of bounds if all arrays are not of the same size.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data junk;
   input x1 - x5  y1-y4;
   array x x:;
   array y y:;
   do over x;
     put x=;
     put y=;
   end;;
datalines;
 1 2 3 4 5 6 7 8 9
 2 3 4 5 6 7 8 9 10
 ;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;ANY use of the array y is going to have issues when you get to the fifth element of X in the above. And if you change it to use Y as the controller then the last element of X never gets processed. Yes the example is trivial but it demonstrates the principal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second is that when you need to conditionally reference an element. When using Do i = 1 to dim(x) you have the ability to check if the element you are processing in x is the such&amp;nbsp;the first&amp;nbsp;with "If i=1 then do" &amp;nbsp;or last: "if &amp;nbsp;i= dim(x) ".&lt;/P&gt;
&lt;P&gt;Also any time when you may need to reference different elements of two arrays or mulitiple elements of the same array&amp;nbsp;at the same time which may occur with ordering the elements of an array or finding&amp;nbsp;the max,min, mean etc of groups of 3 or 4 elements is just not feasible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the DO OVER code is not even documented in SAS since version 8.&lt;/P&gt;
&lt;P&gt;I would pretty much restrict the use of DO OVER&amp;nbsp;to single operations on single arrays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I shudder trying to use Do Over with a two dimensional array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 07 Nov 2016 16:15:02 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-11-07T16:15:02Z</dc:date>
    <item>
      <title>Passing a Period through an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Period-through-an-array/m-p/309412#M66537</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data = SASHELP.ELECTRIC order=varnum; run;

data Have;
	set SASHELP.ELECTRIC(keep = Revenue Coal Hydro);
		array var Revenue   Coal    Hydro;
		array fmt DOLLAR10  COMMA10 COMMA10;
		array new t_Revenue t_coal  t_Hydro;
		
		do over var;
			new=put(var,fmt);
		end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How do I pass a comma through to my fmt array?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OR&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there an easier way to grab the formatted value lables and put into a new variable??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2016 21:02:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-Period-through-an-array/m-p/309412#M66537</guid>
      <dc:creator>SAShole</dc:creator>
      <dc:date>2016-11-04T21:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a Period through an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Period-through-an-array/m-p/309424#M66545</link>
      <description>&lt;P&gt;The functions PUTN and PUTC allow you to use the value of a text variable as the format.&lt;/P&gt;
&lt;P&gt;Also the Do Over array statement isn't reliable when addressing multiple arrays.&lt;/P&gt;
&lt;P&gt;A temporary array is a better way to use a list of values. The way you declared the FMT array it was expecting variables named Dollar10 and Comma10 not the values. Note that the values for the format include the . in the text vale.&lt;/P&gt;
&lt;P&gt;I think you may be looking for something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
	set SASHELP.ELECTRIC(keep = Revenue Coal Hydro);
		array var Revenue   Coal    Hydro;
		array fmt {3} $10 _temporary_ ( "DOLLAR10.",  "COMMA10." ,"COMMA10." );
		array new t_Revenue t_coal  t_Hydro;
		
		do i = 1 to dim(var);
			new[i]=putn(var[i],fmt[i]);
		end;
      drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 15:55:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-Period-through-an-array/m-p/309424#M66545</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-07T15:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a Period through an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Period-through-an-array/m-p/309630#M66693</link>
      <description>&lt;P&gt;can you tell me more about the dangers of multiple arrays in a do-over loop?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2016 23:36:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-Period-through-an-array/m-p/309630#M66693</guid>
      <dc:creator>SAShole</dc:creator>
      <dc:date>2016-11-06T23:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a Period through an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Period-through-an-array/m-p/309760#M66745</link>
      <description>&lt;P&gt;The first issue&amp;nbsp;is it becomes very easy to generate an error of array out of bounds if all arrays are not of the same size.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data junk;
   input x1 - x5  y1-y4;
   array x x:;
   array y y:;
   do over x;
     put x=;
     put y=;
   end;;
datalines;
 1 2 3 4 5 6 7 8 9
 2 3 4 5 6 7 8 9 10
 ;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;ANY use of the array y is going to have issues when you get to the fifth element of X in the above. And if you change it to use Y as the controller then the last element of X never gets processed. Yes the example is trivial but it demonstrates the principal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second is that when you need to conditionally reference an element. When using Do i = 1 to dim(x) you have the ability to check if the element you are processing in x is the such&amp;nbsp;the first&amp;nbsp;with "If i=1 then do" &amp;nbsp;or last: "if &amp;nbsp;i= dim(x) ".&lt;/P&gt;
&lt;P&gt;Also any time when you may need to reference different elements of two arrays or mulitiple elements of the same array&amp;nbsp;at the same time which may occur with ordering the elements of an array or finding&amp;nbsp;the max,min, mean etc of groups of 3 or 4 elements is just not feasible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the DO OVER code is not even documented in SAS since version 8.&lt;/P&gt;
&lt;P&gt;I would pretty much restrict the use of DO OVER&amp;nbsp;to single operations on single arrays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I shudder trying to use Do Over with a two dimensional array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 16:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-Period-through-an-array/m-p/309760#M66745</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-07T16:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a Period through an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-Period-through-an-array/m-p/310105#M66836</link>
      <description>&lt;P&gt;Thanks! That example makes the dangers clear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll be using explicit array references from now on &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 14:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-Period-through-an-array/m-p/310105#M66836</guid>
      <dc:creator>SAShole</dc:creator>
      <dc:date>2016-11-08T14:55:33Z</dc:date>
    </item>
  </channel>
</rss>

