<?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: data step calculation with arrays in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/data-step-calculation-with-arrays/m-p/402976#M25862</link>
    <description>apologies. that was actually a wrong calculation on my end. Had to scrap the approach. Thanks for the help!</description>
    <pubDate>Tue, 10 Oct 2017 22:34:24 GMT</pubDate>
    <dc:creator>eemrun</dc:creator>
    <dc:date>2017-10-10T22:34:24Z</dc:date>
    <item>
      <title>data step calculation with arrays</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/data-step-calculation-with-arrays/m-p/393416#M25370</link>
      <description>&lt;P&gt;Rookie here. I am trying to evaluate the following. The idea is that this should evaluate lp with an initial value (given in the first equation) and then loop to populate with those fixed values (e.g. kA, kB) and array values of A, B, C values. Initial values are zero for array AX, BX and CX. When I run it, i get zeroes for all instances of A, B and C and no LP values. Any idea where i am wrong?&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 test1 (drop = i);&lt;BR /&gt;array AX[128] A1-A128;&lt;BR /&gt;array BX[128] B1-V128;&lt;BR /&gt;array CX[128] C1-T128;&lt;BR /&gt;&lt;BR /&gt;do i = 1 to 128;&lt;BR /&gt;AX[i] = 0;&lt;BR /&gt;BX[i] = 0;&lt;BR /&gt;CX[i] = 0;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data test2 ;
set test1;
array AX[128] A1-A128;
array BX[128] B1-V128;
array CX[128] C1-T128;
kA = 23.99196;
kB = 21.04797;
kC = 54.98294;

lp = (log(kA) * 127/2) + (log(kB) * 127/2) + (log(kC) * 127/2);
       do i=2 to 128;
              lp = lp - kA * (AX[i] - AX[i-1])**2 / 2
                                  - kB * (BX[i] -BX[i-1])**2 / 2
                                                - kC * (CX[i] - CX[i-1])**2 / 2;
		end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 02:23:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/data-step-calculation-with-arrays/m-p/393416#M25370</guid>
      <dc:creator>eemrun</dc:creator>
      <dc:date>2017-09-06T02:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: data step calculation with arrays</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/data-step-calculation-with-arrays/m-p/393419#M25371</link>
      <description>&lt;P&gt;Few typos in the code, please correct it.&lt;/P&gt;&lt;P&gt;B1-V128 should be B1-B128&lt;/P&gt;&lt;P&gt;C1-T128 should be C1-C128&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After this correction, if I run the code I get lp =&lt;SPAN&gt;649.70316134 because of first equation&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;lp = (log(kA) * 127/2) + (log(kB) * 127/2) + (log(kC) * 127/2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Rest main loop is not helping becuase all A1-A128, B1-B128 and C1-C128 are zero.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Let me know what are you looking for.&amp;nbsp;&lt;/SPAN&gt;&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 test1 (drop = i);
array AX[128] A1-A128;
array BX[128] B1-B128;
array CX[128] C1-C128;
do i = 1 to 128;
AX[i] = 0;
BX[i] = 0;
CX[i] = 0;
end;

run;



data test2(keep=lp) ;
set test1;
array AX[128] A1-A128;
array BX[128] B1-B128;
array CX[128] C1-C128;
kA = 23.99196;
kB = 21.04797;
kC = 54.98294;

lp = (log(kA) * 127/2) + (log(kB) * 127/2) + (log(kC) * 127/2);
       do i=2 to 128;
              lp = lp - kA * (AX[i] - AX[i-1])**2 / 2
                                  - kB * (BX[i] -BX[i-1])**2 / 2
                                                - kC * (CX[i] - CX[i-1])**2 / 2;
		end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2017 03:26:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/data-step-calculation-with-arrays/m-p/393419#M25371</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2017-09-06T03:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: data step calculation with arrays</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/data-step-calculation-with-arrays/m-p/402976#M25862</link>
      <description>apologies. that was actually a wrong calculation on my end. Had to scrap the approach. Thanks for the help!</description>
      <pubDate>Tue, 10 Oct 2017 22:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/data-step-calculation-with-arrays/m-p/402976#M25862</guid>
      <dc:creator>eemrun</dc:creator>
      <dc:date>2017-10-10T22:34:24Z</dc:date>
    </item>
  </channel>
</rss>

