<?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: one dimensional and two dimensional in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Arrays-one-dimensional-and-two-dimensional/m-p/601830#M174133</link>
    <description>&lt;P&gt;Did you try running the code?&lt;/P&gt;
&lt;P&gt;Did you get the expected result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any values of 0 in the X array? You might want to fix the division by zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I might suggest for limits so it is a bit more obvious which array size is controlling the limit. Also if later you have more or fewer&amp;nbsp;variables in the array then you don't need to change the array limit.&lt;/P&gt;
&lt;PRE&gt;DO i=1  TO dim(www);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normally the only place I personally use the { } braces are in array definitions and then use [ ] when referencing array elements but that is mostly a style choice.&lt;/P&gt;</description>
    <pubDate>Tue, 05 Nov 2019 21:46:28 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-11-05T21:46:28Z</dc:date>
    <item>
      <title>Arrays: one dimensional and two dimensional</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays-one-dimensional-and-two-dimensional/m-p/601825#M174130</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;Let's say that in the data set I have there are 13 variables called : ID ,X0-X11&lt;/P&gt;&lt;P&gt;Let's say that the task is to create a series of new 11 variables called W1-W11 that their values will be as following:&lt;/P&gt;&lt;P&gt;W1=(X1-X0)/X0;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;W2=(X2-X1)/X1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;and so on&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;W11=(X11-X10)/X10;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is the way to write it by defining Arrays?&lt;/P&gt;&lt;P&gt;How many one dimensional-Arrays should be defined?&lt;/P&gt;&lt;P&gt;What is the way to do it by defining one two-&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;dimensional-Array&lt;/SPAN&gt;?&lt;/P&gt;&lt;P&gt;I am trying to write the code. What do you think? Is it correct?&lt;/P&gt;&lt;P&gt;Please note that I defined two one-dimensional arrays but with different dim (For Array XXX the dim is 12 and for WWW the dim is 11)&lt;/P&gt;&lt;P&gt;Data Tbl2;&lt;/P&gt;&lt;P&gt;SET tbl1;&lt;/P&gt;&lt;P&gt;ARRAY&amp;nbsp; XXX(12)&amp;nbsp; X0-X11;&lt;/P&gt;&lt;P&gt;ARRAY WWW(11) W1-W11;&lt;/P&gt;&lt;P&gt;DO i=1&amp;nbsp; TO 11;&lt;/P&gt;&lt;P&gt;WWW{i}=(XXX{i+1}-XXX{i})/&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;XXX{i}&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2019 21:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays-one-dimensional-and-two-dimensional/m-p/601825#M174130</guid>
      <dc:creator>DaveStar</dc:creator>
      <dc:date>2019-11-05T21:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays: one dimensional and two dimensional</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays-one-dimensional-and-two-dimensional/m-p/601830#M174133</link>
      <description>&lt;P&gt;Did you try running the code?&lt;/P&gt;
&lt;P&gt;Did you get the expected result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any values of 0 in the X array? You might want to fix the division by zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I might suggest for limits so it is a bit more obvious which array size is controlling the limit. Also if later you have more or fewer&amp;nbsp;variables in the array then you don't need to change the array limit.&lt;/P&gt;
&lt;PRE&gt;DO i=1  TO dim(www);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normally the only place I personally use the { } braces are in array definitions and then use [ ] when referencing array elements but that is mostly a style choice.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2019 21:46:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays-one-dimensional-and-two-dimensional/m-p/601830#M174133</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-11-05T21:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays: one dimensional and two dimensional</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays-one-dimensional-and-two-dimensional/m-p/601835#M174136</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292395"&gt;@DaveStar&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Yes, you can use both two 1-dimensional arrays and one 2-dimensional array for the purpose.&lt;/P&gt;
&lt;P&gt;However, in the latter case you'd need to add a dummy variable because the number of variables in every row and column must be identical. It stands to reason, as a 2-dim array is a rectangular matrix, and you cannot have it with a corner cell simply absent. Compare the second and third steps below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tb1 ;                                                                                                                              
 array xxx [12] x0-x11 (0 1 . 2 3 4 5 . 6 0 8 7) ;                                                                                      
run ;                                                                                                                                   
                                                                                                                                        
data tbl2 ;                                                                                                                             
  set tb1 ;                                                                                                                             
  array xxx [12] x0-x11 ;                                                                                                               
  array www [11] w1-w11 ;                                                                                                               
  do i = 1 to dim (xxx) - 1 ;                                                                                                           
    www[i]= divide (xxx[i+1] - xxx[i], xxx[i]) ;                                                                                        
  end ;                                                                                                                                 
run ;                                                                                                                                   
                                                                                                                                        
data tbl2 (drop = _:) ;                                                                                                                 
  set tb1 ;                                                                                                                             
  array xw [2, 12] x0-x11 w1-w11 _wdummy ;                                                                                              
  do i = 1 to dim (xw, 2) - 1 ;                                                                                                         
    xw[2,i]= divide (xw[1,i+1] - xw[1,i], xw[1,i]) ;                                                                                    
  end ;                                                                                                                                 
run ;          
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Heed also what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;has said. First, compared to simple square brackets, curly braces are pain both to type and look at. Personally, I always use square brackets both in array definitions and references. Second, the DIVIDE function is much preferable to the division operator in terms of auto-handling division by zero and by null. (If you run the above code, you'll see some "missing values generated" notes in the log but they result from the minus (-) operator.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D. &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2019 22:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays-one-dimensional-and-two-dimensional/m-p/601835#M174136</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-11-05T22:14:54Z</dc:date>
    </item>
  </channel>
</rss>

