<?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: Compute formula with sum of log and two loops in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compute-formula-with-sum-of-log-and-two-loops/m-p/593029#M170123</link>
    <description>&lt;P&gt;That does work, only I mistakenly did 10+k instead of 10*K, maybe we should both edit this. And I forgot to mention I multiply the expected probabilities by 100.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Oct 2019 13:57:32 GMT</pubDate>
    <dc:creator>SarahDew</dc:creator>
    <dc:date>2019-10-01T13:57:32Z</dc:date>
    <item>
      <title>Compute formula with sum of log and two loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-formula-with-sum-of-log-and-two-loops/m-p/593022#M170120</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to apply the following formula to an input of the numbers 1 to 9 (=d) and n=2 (so k = 0 to 9):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://wikimedia.org/api/rest_v1/media/math/render/svg/3a338ec141d9bd3c387052fb9ad1f0ef6ab59a63" border="0" alt="{\displaystyle \sum _{k=10^{n-2}}^{10^{n-1}-1}\log _{10}\left(1+{\frac {1}{10k+d}}\right)}" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am almost there, but I figure I need to add a second step somewhere to loop over the k. I currently use two do loops, for k and d, but I don't see how to get one loop within the sum, and one loop applied to the sum. I get the expected for each combination of digits, but I still need the sum of&amp;nbsp; the 'expected' where D remains the same. If I could also add a conversion from n to k, meaning I do "%let n=2" and then SAS computes the range of k, that would be even better.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my attempt:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data EXPECTED_D2;
 FORMAT EXPECTED 8.3;
 DO D = 0 TO 9;
 DO K = 1 TO 9;
 EXPECTED=sum(LOG10(1+(1/((10*K)+D))));
 OUTPUT;
 END;
 END;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;desired result:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data EXPECTED_D;
 input D EXPECTED;
 datalines;
 0 11.97
 1 11.39
 2 10.88
 3 10.43
 4 10.03
 5 9.67
 6 9.34
 7 9.04
 8 8.76
 9 8.50
;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 13:58:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-formula-with-sum-of-log-and-two-loops/m-p/593022#M170120</guid>
      <dc:creator>SarahDew</dc:creator>
      <dc:date>2019-10-01T13:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: Compute formula with sum of log and two loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-formula-with-sum-of-log-and-two-loops/m-p/593026#M170121</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/244638"&gt;@SarahDew&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to apply the following formula to an input of the numbers 1 to 9 (=d) and n=2 (so k = 0 to 9):&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://wikimedia.org/api/rest_v1/media/math/render/svg/3a338ec141d9bd3c387052fb9ad1f0ef6ab59a63" border="0" alt="{\displaystyle \sum _{k=10^{n-2}}^{10^{n-1}-1}\log _{10}\left(1+{\frac {1}{10k+d}}\right)}" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am almost there, but I figure I need to add a second step somewhere to loop over the k. I currently use two do loops, for k and d, but I don't see how to get one loop within the sum, and one loop applied to the sum. I get the expected for each combination of digits, but I still need the sum of&amp;nbsp; the 'expected' where D remains the same. If I could also add a conversion from n to k, meaning I do "%let n=2" and then SAS computes the range of k, that would be even better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Stay away from macro variables here. They are of no help in this situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data EXPECTED_D2;
 FORMAT EXPECTED 8.3;
 DO D = 0 TO 9;
 expected=0;
 DO K = 1 TO 9;
 EXPECTED=expected+LOG10(1+(1/((10+K)+D)));
 END;
  OUTPUT;
 END;
 drop k;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This doesn't give the same answers you provided, I don't know why, since it uses the exact same formula for EXPECTED that you are using.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 13:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-formula-with-sum-of-log-and-two-loops/m-p/593026#M170121</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-01T13:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Compute formula with sum of log and two loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-formula-with-sum-of-log-and-two-loops/m-p/593028#M170122</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/244638"&gt;@SarahDew&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;10k is 10*k, not 10+k. So, very similar to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data expected_d2(drop=k);
do d = 0 to 9;
  expected=0;
  do k = 1 to 9;
    expected+log10(1+(1/(10*k+d)));
  end;
  output;
end;
format expected percent8.2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Oct 2019 13:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-formula-with-sum-of-log-and-two-loops/m-p/593028#M170122</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-10-01T13:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Compute formula with sum of log and two loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-formula-with-sum-of-log-and-two-loops/m-p/593029#M170123</link>
      <description>&lt;P&gt;That does work, only I mistakenly did 10+k instead of 10*K, maybe we should both edit this. And I forgot to mention I multiply the expected probabilities by 100.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 13:57:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-formula-with-sum-of-log-and-two-loops/m-p/593029#M170123</guid>
      <dc:creator>SarahDew</dc:creator>
      <dc:date>2019-10-01T13:57:32Z</dc:date>
    </item>
  </channel>
</rss>

