<?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: Calculate the average of a variable from two different rows in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Calculate-the-average-of-a-variable-from-two-different-rows/m-p/615617#M18802</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288275"&gt;@GLucio&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n0l66p5oqex1f2n1quuopdvtcjqb.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;LAG function&lt;/A&gt; to refer to a preceding value:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Outstanding;
cards;
6000000
21000000
30000000
;

data want;
set have;
Service_Fee=mean(Outstanding, lag(Outstanding))*0.000625;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 07 Jan 2020 11:01:15 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2020-01-07T11:01:15Z</dc:date>
    <item>
      <title>Calculate the average of a variable from two different rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-the-average-of-a-variable-from-two-different-rows/m-p/615613#M18801</link>
      <description>&lt;P&gt;Hey there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a quick doubt. I need to generate a column that is the result of another one, in this case Service_Fee, where the value of each cell should be the average between the value of the variable Outstanding in that row and the value of the previous row. And then multiple that value with a constant of 0.000625.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, how it should look like in SAS:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Row&amp;nbsp; &amp;nbsp; &amp;nbsp;Outstanding&amp;nbsp; &amp;nbsp; &amp;nbsp;Service_Fee&lt;BR /&gt;&amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6 000 000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 750,00&lt;BR /&gt;&amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 21 000 000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8 437,50&amp;nbsp;&lt;BR /&gt;&amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30 000.000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15 937,50&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Service_fee (row=2) = ((21 000 000 + 6 000 000)/2)*0,000625 =&amp;nbsp;8 437,50&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 10:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-the-average-of-a-variable-from-two-different-rows/m-p/615613#M18801</guid>
      <dc:creator>GLucio</dc:creator>
      <dc:date>2020-01-07T10:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the average of a variable from two different rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-the-average-of-a-variable-from-two-different-rows/m-p/615617#M18802</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288275"&gt;@GLucio&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n0l66p5oqex1f2n1quuopdvtcjqb.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;LAG function&lt;/A&gt; to refer to a preceding value:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Outstanding;
cards;
6000000
21000000
30000000
;

data want;
set have;
Service_Fee=mean(Outstanding, lag(Outstanding))*0.000625;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jan 2020 11:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-the-average-of-a-variable-from-two-different-rows/m-p/615617#M18802</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-01-07T11:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the average of a variable from two different rows</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-the-average-of-a-variable-from-two-different-rows/m-p/615622#M18804</link>
      <description>&lt;P&gt;Thanks a lot &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; It works perfectly&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 11:07:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-the-average-of-a-variable-from-two-different-rows/m-p/615622#M18804</guid>
      <dc:creator>GLucio</dc:creator>
      <dc:date>2020-01-07T11:07:57Z</dc:date>
    </item>
  </channel>
</rss>

