<?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: Sum of variables in an array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640674#M190897</link>
    <description>&lt;P&gt;please try the below code, instead of using sum(of ) changed to &lt;CODE class=" language-sas"&gt;sum(prob1,prob(i-1)&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;

array piM {52} pi1-pi52;
array prob {52} prob1-prob52;
do i=1 to 52;
piM[i]=0.5*pdf('normal',i,26,10);
if i=1 then prob[i]=pim[i]; 
if i&amp;gt;1 then prob[i]=piM[i]/(1-sum(prob1,prob(i-1)));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 17 Apr 2020 11:15:27 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2020-04-17T11:15:27Z</dc:date>
    <item>
      <title>Sum of variables in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640667#M190893</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm trying to sum variables prob1 to prob[i-1] from an array. For some reasons, SAS doesn't recognize that it's a range of variable, so I got an error message saying that a , or ) is expected. What should I do?&lt;/P&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;

array piM {52} pi1-pi52;
array prob {52} prob1-prob52;
do i=1 to 52;
piM[i]=0.5*pdf('normal',i,26,10);
if i=1 then prob[i]=pim[i]; if i&amp;gt;1 then prob[i]=piM[i]/(1-sum(of prob[1]-prob[i-1]));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Apr 2020 10:57:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640667#M190893</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2020-04-17T10:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640671#M190895</link>
      <description>&lt;P&gt;Show us the log. Include the entire data step code and NOTES, WARNINGS and ERRORs. Do not chop anything out of the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When providing the log, it is critical that you maintain the formatting of the log so we can see it exactly as SAS showed it to you, making it easier for us to use. To maintain the formatting of the log, click on the &amp;lt;/&amp;gt; icon and paste the log as text into the window that appears. DO NOT SKIP THIS STEP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, for future reference, saying there is an error message but not showing it to us just slows you down, because we will ask to see the error message.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 10:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640671#M190895</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-17T10:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640673#M190896</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm creating my own data.&lt;/P&gt;
&lt;P&gt;The log complete log message is the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;72&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;73 data test2;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;74&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;75 array piM {52} pi1-pi52;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;76 array prob {52} prob1-prob52;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;77 do i=1 to 52;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;78 piM[i]=0.5*pdf('normal',i,26,10);&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;79 if i=1 then prob[i]=pim[i]; if i&amp;gt;2 then prob[i]=piM[i]/(1-sum(of prob[1]-prob[i-1]));&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;_&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;22&lt;/DIV&gt;
&lt;DIV id="sasLogError1_1587120901103" class="sasError"&gt;ERROR 22-322: Syntax error, expecting one of the following: ), ','.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;80 end;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;81 run;&lt;/DIV&gt;</description>
      <pubDate>Fri, 17 Apr 2020 10:55:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640673#M190896</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2020-04-17T10:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640674#M190897</link>
      <description>&lt;P&gt;please try the below code, instead of using sum(of ) changed to &lt;CODE class=" language-sas"&gt;sum(prob1,prob(i-1)&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;

array piM {52} pi1-pi52;
array prob {52} prob1-prob52;
do i=1 to 52;
piM[i]=0.5*pdf('normal',i,26,10);
if i=1 then prob[i]=pim[i]; 
if i&amp;gt;1 then prob[i]=piM[i]/(1-sum(prob1,prob(i-1)));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Apr 2020 11:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640674#M190897</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-04-17T11:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640677#M190898</link>
      <description>No. For i=4, I want for instance the sum of prob1+prob2+prob3. In your solution, it just sums up prob1+prob3.</description>
      <pubDate>Fri, 17 Apr 2020 11:19:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640677#M190898</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2020-04-17T11:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640680#M190900</link>
      <description>&lt;P&gt;You didn't follow the instructions to show us the log, and so it is not very interpretable the way you showed it. Please show us the log by clicking on the &amp;lt;/&amp;gt; icon.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 11:28:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640680#M190900</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-17T11:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640682#M190901</link>
      <description>&lt;PRE&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data test2;
74
75 array piM {52} pi1-pi52;
76 array prob {52} prob1-prob52;
77 do i=1 to 52;
78 piM[i]=0.5*pdf('normal',i,26,10);
79 if i=1 then prob[i]=pim[i]; if i&amp;gt;2 then prob[i]=piM[i]/(1-sum(of prob[1]-prob[i-1]));
_
22
ERROR 22-322: Syntax error, expecting one of the following: ), ','.
 
80 end;
81 run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Apr 2020 11:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640682#M190901</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2020-04-17T11:31:47Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640683#M190902</link>
      <description>&lt;P&gt;Please try the updated code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;

array piM {52} pi1-pi52;
array prob {52} prob1-prob52;
do i=1 to 52;
piM[i]=0.5*pdf('normal',i,26,10);
if i=1 then prob[i]=pim[i]; 
if i&amp;gt;1 then prob[i]=piM[i]/(1-sum(of prob(i-1)));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Apr 2020 11:33:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640683#M190902</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-04-17T11:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640689#M190904</link>
      <description>&lt;P&gt;Thanks but I wanted the log from SAS pasted into the &amp;lt;/&amp;gt; window, not the log (which is not properly formatted) from your earlier positing pasted into the &amp;lt;/&amp;gt; window.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Then you will see this, which exactly pinpoints the problem&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1     data test2;
2
3     array piM {52} pi1-pi52;
4     array prob {52} prob1-prob52;
5     do i=1 to 52;
6     piM[i]=0.5*pdf('normal',i,26,10);
7     if i=1 then prob[i]=pim[i]; if i&amp;gt;2 then prob[i]=piM[i]/(1-sum(of prob[1]-prob[i-1]));
                                                                              -
                                                                              22
ERROR 22-322: Syntax error, expecting one of the following: ), ','.

8     end;
9     run;
&lt;/PRE&gt;
&lt;P&gt;You can't use subtraction with sum(of ...)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You probably want:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sum(prob[1],-prob[i-1])&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 11:48:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640689#M190904</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-17T11:48:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640699#M190910</link>
      <description>&lt;P&gt;With "of", you either need to use a comprehensive list of elements, or the whole array; you cannot address a subset of the array as you intended.&lt;/P&gt;
&lt;P&gt;Keep a running sum of your prob array:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
array pim {52} pi1-pi52;
array prob {52} prob1-prob52;
sumprob = 0;
do i = 1 to 52;
  pim[i] = 0.5 * pdf('normal',i,26,10);
  if i = 1
  then prob[i] = pim[i];
  else prob[i] = pim[i] / (1 - sumprob);
  sumprob = sum(sumprob,prob[i]);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Apr 2020 12:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640699#M190910</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-17T12:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of variables in an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640700#M190911</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33143"&gt;@Demographer&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;No. For i=4, I want for instance the sum of prob1+prob2+prob3. In your solution, it just sums up prob1+prob3.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is not what you accepted as solution. The accepted solution results in prob1 - prob3.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 12:08:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-of-variables-in-an-array/m-p/640700#M190911</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-17T12:08:22Z</dc:date>
    </item>
  </channel>
</rss>

