<?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: reverse retaining with example in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/reverse-retaining-with-example/m-p/599374#M173014</link>
    <description>262814.91-43810.92-43810.92 ...etc. 262814.91 Number came from the same Account numbers cummulated Amt fields. Thanks for your help</description>
    <pubDate>Fri, 25 Oct 2019 15:30:41 GMT</pubDate>
    <dc:creator>ger15xxhcker</dc:creator>
    <dc:date>2019-10-25T15:30:41Z</dc:date>
    <item>
      <title>reverse retaining with example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reverse-retaining-with-example/m-p/599314#M172983</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you help me this group retaining? How can i solve it? I hope its a good exemple.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Would really appreciate any suggestions. Thank you.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data&amp;nbsp;start_dataset;

input&amp;nbsp;account date amt sum;

datalines;

510046500&amp;nbsp;&amp;nbsp; 20190416&amp;nbsp;&amp;nbsp;&amp;nbsp; 43728.16&amp;nbsp;&amp;nbsp;&amp;nbsp; 6262.12

510046500&amp;nbsp;&amp;nbsp; 20190516&amp;nbsp;&amp;nbsp;&amp;nbsp; 43771.27&amp;nbsp;&amp;nbsp;&amp;nbsp; 37577.49

510046500&amp;nbsp;&amp;nbsp; 20190614&amp;nbsp;&amp;nbsp;&amp;nbsp; 43771.27&amp;nbsp;&amp;nbsp;&amp;nbsp; 43771.27

510046500&amp;nbsp;&amp;nbsp; 20190716&amp;nbsp;&amp;nbsp;&amp;nbsp; 43771.27&amp;nbsp;&amp;nbsp;&amp;nbsp; 43771.27

510046500&amp;nbsp;&amp;nbsp; 20190816&amp;nbsp;&amp;nbsp;&amp;nbsp; 43810.92&amp;nbsp;&amp;nbsp;&amp;nbsp; 43810.92

510046500&amp;nbsp;&amp;nbsp; 20190916&amp;nbsp;&amp;nbsp;&amp;nbsp; 43810.92&amp;nbsp;&amp;nbsp;&amp;nbsp; 43810.92

510046500&amp;nbsp;&amp;nbsp; 20191016&amp;nbsp;&amp;nbsp;&amp;nbsp; 43810.92&amp;nbsp;&amp;nbsp;&amp;nbsp; 43810.92

;

run;



/*

If the difference in sum field &amp;lt;0 then stop end drop this record. Sum can not be negative.

sum(all same acocunt amt) - previus date amt

*/



data&amp;nbsp;final;

input&amp;nbsp;account date amt sum;

datalines;

510046500&amp;nbsp;&amp;nbsp; 20190416&amp;nbsp;&amp;nbsp;&amp;nbsp; 43728.16&amp;nbsp;&amp;nbsp;&amp;nbsp; 68.34

510046500&amp;nbsp;&amp;nbsp; 20190516&amp;nbsp;&amp;nbsp;&amp;nbsp; 43771.27&amp;nbsp;&amp;nbsp;&amp;nbsp; 43839.61

510046500&amp;nbsp;&amp;nbsp; 20190614&amp;nbsp;&amp;nbsp;&amp;nbsp; 43771.27&amp;nbsp;&amp;nbsp;&amp;nbsp; 87610.88

510046500&amp;nbsp;&amp;nbsp; 20190716&amp;nbsp;&amp;nbsp;&amp;nbsp; 43771.27&amp;nbsp;&amp;nbsp;&amp;nbsp; 131382.15

510046500&amp;nbsp;&amp;nbsp; 20190816&amp;nbsp;&amp;nbsp;&amp;nbsp; 43810.92&amp;nbsp;&amp;nbsp;&amp;nbsp; 175193.07

510046500&amp;nbsp;&amp;nbsp; 20190916&amp;nbsp;&amp;nbsp;&amp;nbsp; 43810.92&amp;nbsp;&amp;nbsp;&amp;nbsp; 219003.99

510046500&amp;nbsp;&amp;nbsp; 20191016&amp;nbsp;&amp;nbsp;&amp;nbsp; 43810.92&amp;nbsp;&amp;nbsp;&amp;nbsp; 262814.91

;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 14:58:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reverse-retaining-with-example/m-p/599314#M172983</guid>
      <dc:creator>ger15xxhcker</dc:creator>
      <dc:date>2019-10-25T14:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: reverse retaining with example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reverse-retaining-with-example/m-p/599368#M173009</link>
      <description>&lt;P&gt;How do you calculate sum in the first observation of a group, and how do you calculate the next ones?&lt;/P&gt;
&lt;P&gt;Right now I can't make sense of your description.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 15:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reverse-retaining-with-example/m-p/599368#M173009</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-25T15:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: reverse retaining with example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reverse-retaining-with-example/m-p/599374#M173014</link>
      <description>262814.91-43810.92-43810.92 ...etc. 262814.91 Number came from the same Account numbers cummulated Amt fields. Thanks for your help</description>
      <pubDate>Fri, 25 Oct 2019 15:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reverse-retaining-with-example/m-p/599374#M173014</guid>
      <dc:creator>ger15xxhcker</dc:creator>
      <dc:date>2019-10-25T15:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: reverse retaining with example</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reverse-retaining-with-example/m-p/599382#M173019</link>
      <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input account :$9. date yymmdd10. amt sum;
format date yymmddd10.;
datalines;
510046500   20190416    43728.16    6262.12
510046500   20190516    43771.27    37577.49
510046500   20190614    43771.27    43771.27
510046500   20190716    43771.27    43771.27
510046500   20190816    43810.92    43810.92
510046500   20190916    43810.92    43810.92
510046500   20191016    43810.92    43810.92
;

proc sort data=have;
by account descending date;
run;

data want;
if 0 then set have;
total_sum = 0;
do until (last.account);
  set have;
  by account;
  total_sum + sum;
end;
do until (last.account);
  set have;
  by account;
  sum = total_sum;
  output;
  total_sum + (-amt);
end;
drop total_sum;
run;

proc sort data=want;
by account date;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;account  	date         	amt          	sum
510046500	2019-04-16	43728.16	68.34
510046500	2019-05-16	43771.27	43839.61
510046500	2019-06-14	43771.27	87610.88
510046500	2019-07-16	43771.27	131382.15
510046500	2019-08-16	43810.92	175193.07
510046500	2019-09-16	43810.92	219003.99
510046500	2019-10-16	43810.92	262814.91
&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Oct 2019 15:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reverse-retaining-with-example/m-p/599382#M173019</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-25T15:48:41Z</dc:date>
    </item>
  </channel>
</rss>

