<?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 accumulating sum in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/accumulating-sum/m-p/633883#M188088</link>
    <description>&lt;P&gt;Hi...I am trying to do a running total for each amount. The BegRevenue is the previous records EndRevenue and the current record's EndRevenue is the records BegRevenue plus the Show Amount. I can't seem to get this to work. Any suggestions....thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    length ShowAmount 8 ;
    format ShowAmount Dollar20.2 ;
    informat ShowAmount Dollar20. ;
    infile datalines4 dlm='7F'x missover dsd;
    input ShowAmount: best32. ;
datalines4;
1550
-1550
1550
-1550
-1550
1550
1775
975
100
-1850
-900
-100
;;;;

data want(drop=_EndRevenue);
	set have;
	retain _EndRevenue;
		if _n_=1 then do;
			BegRevenue = 0;
			EndRevenue = ShowAmount;
			_EndRevenue = EndRevenue;
			end;
		else do;
			BegRevenue = _EndRevenue;
			EndRevenue = (BegRevenue+ShowAmount);
			BegRevenue = _EndRevenue;
			end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ShowAmount	BegRevenue	EndRevenue
$1,550.00	0	1550
-$1,550.00	1550	0
$1,550.00	1550	3100
-$1,550.00	1550	0
-$1,550.00	1550	0
$1,550.00	1550	3100
$1,775.00	1550	3325
$975.00	1550	2525
$100.00	1550	1650
-$1,850.00	1550	-300
-$900.00	1550	650
-$100.00	1550	1450
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 21 Mar 2020 21:40:20 GMT</pubDate>
    <dc:creator>twildone</dc:creator>
    <dc:date>2020-03-21T21:40:20Z</dc:date>
    <item>
      <title>accumulating sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/accumulating-sum/m-p/633883#M188088</link>
      <description>&lt;P&gt;Hi...I am trying to do a running total for each amount. The BegRevenue is the previous records EndRevenue and the current record's EndRevenue is the records BegRevenue plus the Show Amount. I can't seem to get this to work. Any suggestions....thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    length ShowAmount 8 ;
    format ShowAmount Dollar20.2 ;
    informat ShowAmount Dollar20. ;
    infile datalines4 dlm='7F'x missover dsd;
    input ShowAmount: best32. ;
datalines4;
1550
-1550
1550
-1550
-1550
1550
1775
975
100
-1850
-900
-100
;;;;

data want(drop=_EndRevenue);
	set have;
	retain _EndRevenue;
		if _n_=1 then do;
			BegRevenue = 0;
			EndRevenue = ShowAmount;
			_EndRevenue = EndRevenue;
			end;
		else do;
			BegRevenue = _EndRevenue;
			EndRevenue = (BegRevenue+ShowAmount);
			BegRevenue = _EndRevenue;
			end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ShowAmount	BegRevenue	EndRevenue
$1,550.00	0	1550
-$1,550.00	1550	0
$1,550.00	1550	3100
-$1,550.00	1550	0
-$1,550.00	1550	0
$1,550.00	1550	3100
$1,775.00	1550	3325
$975.00	1550	2525
$100.00	1550	1650
-$1,850.00	1550	-300
-$900.00	1550	650
-$100.00	1550	1450
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Mar 2020 21:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/accumulating-sum/m-p/633883#M188088</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2020-03-21T21:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: accumulating sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/accumulating-sum/m-p/633886#M188090</link>
      <description>&lt;P&gt;I presume you are showing the numbers you got, instead of what you want.&amp;nbsp; Here is a program that generates what I understand to be your objective:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    length ShowAmount 8 ;
    format ShowAmount Dollar20.2 ;
    informat ShowAmount Dollar20. ;
    infile datalines4 dlm='7F'x missover dsd;
    input ShowAmount: best32. ;
datalines4;
1550
-1550
1550
-1550
-1550
1550
1775
975
100
-1850
-900
-100
;;;;

data want;
  set have;
  retain begrevenue 0;
  endrevenue=begrevenue+showamount;
  output;
  begrevenue=endrevenue;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "trick" here is to output the current record, and then update begrevenue in preparation for the next record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Mar 2020 22:15:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/accumulating-sum/m-p/633886#M188090</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-03-21T22:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: accumulating sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/accumulating-sum/m-p/633893#M188094</link>
      <description>Hi..Mkeintz….Yes you are right. That is what I was wanting...thanks for your help...</description>
      <pubDate>Sat, 21 Mar 2020 22:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/accumulating-sum/m-p/633893#M188094</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2020-03-21T22:38:04Z</dc:date>
    </item>
  </channel>
</rss>

