<?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: How to Allocate Recovery Amount Value to loss amount in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Allocate-Recovery-Amount-Value-to-loss-amount/m-p/835044#M330095</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data loss ;
  input ID Loss_amount :comma.;
cards;
100 10,000
100 15,000
100 5,000
;

data recovery;
  input ID Recovery_amount :comma.;
cards;
100 20,000
;
data want;
  merge loss recovery ;
  by id;
  if first.id then cum_lost=0 ;
  cum_lost+Loss_amount;
  if Recovery_amount&amp;gt;=cum_lost then want=Loss_amount;
   else want=ifn(cum_lost-Recovery_amount&amp;lt;Loss_amount,Loss_amount-cum_lost+Recovery_amount,0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 25 Sep 2022 11:02:30 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-09-25T11:02:30Z</dc:date>
    <item>
      <title>How to Allocate Recovery Amount Value to loss amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Allocate-Recovery-Amount-Value-to-loss-amount/m-p/835022#M330079</link>
      <description>&lt;P&gt;Hello Fellow SAS Developers,&lt;/P&gt;&lt;P&gt;I am trying to merge two tables:-&lt;/P&gt;&lt;P&gt;Loss table which consists of two columns i.e ID and Loss amount&lt;/P&gt;&lt;P&gt;ID Loss_amount&lt;BR /&gt;100 10,000&lt;BR /&gt;100 15,000&lt;BR /&gt;100 5,000&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Recovery Table which consists of two columns i.e ID and recovery amount&lt;/P&gt;&lt;P&gt;ID Recovery_amount&lt;BR /&gt;100 20,000&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I need to combine both the tables and the output should be in such a manner that recovery amount&lt;BR /&gt;is the maximum of loss amount and the remaining amount is passed on to the next record.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;For eg:-&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp;Loss_amount Recovery_amount&lt;BR /&gt;100&amp;nbsp; &amp;nbsp;10,000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10,000&lt;BR /&gt;100&amp;nbsp; &amp;nbsp;15,000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10,000&lt;BR /&gt;100&amp;nbsp; &amp;nbsp; 5,000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Sep 2022 20:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Allocate-Recovery-Amount-Value-to-loss-amount/m-p/835022#M330079</guid>
      <dc:creator>anshul_9</dc:creator>
      <dc:date>2022-09-24T20:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to Allocate Recovery Amount Value to loss amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Allocate-Recovery-Amount-Value-to-loss-amount/m-p/835030#M330084</link>
      <description>&lt;P&gt;What is the formula for calculating the new recovery_amount? In the first observation, you subtract the loss (10000) from 20000, leaving 10000. So in the second observation, 10000 - 15000 should result in 0, as you obviously want to stop at zero.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Sep 2022 03:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Allocate-Recovery-Amount-Value-to-loss-amount/m-p/835030#M330084</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-25T03:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to Allocate Recovery Amount Value to loss amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Allocate-Recovery-Amount-Value-to-loss-amount/m-p/835034#M330087</link>
      <description>&lt;P&gt;You need another variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data loss ;
  input ID Loss_amount :comma.;
cards;
100 10,000
100 15,000
100 5,000
;

data recovery;
  input ID Recovery_amount :comma.;
cards;
100 20,000
;

data want;
  merge loss(in=in1) recovery(in=in2) ;
  by id;
  recovered = min(loss_amount,recovery_amount);
  output;
  recovery_amount=max(0,recovery_amount-recovered);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;               Loss_    Recovery_
Obs     ID    amount      amount     recovered

 1     100     10000      20000        10000
 2     100     15000      10000        10000
 3     100      5000          0            0
&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Sep 2022 05:18:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Allocate-Recovery-Amount-Value-to-loss-amount/m-p/835034#M330087</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-25T05:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to Allocate Recovery Amount Value to loss amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Allocate-Recovery-Amount-Value-to-loss-amount/m-p/835044#M330095</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data loss ;
  input ID Loss_amount :comma.;
cards;
100 10,000
100 15,000
100 5,000
;

data recovery;
  input ID Recovery_amount :comma.;
cards;
100 20,000
;
data want;
  merge loss recovery ;
  by id;
  if first.id then cum_lost=0 ;
  cum_lost+Loss_amount;
  if Recovery_amount&amp;gt;=cum_lost then want=Loss_amount;
   else want=ifn(cum_lost-Recovery_amount&amp;lt;Loss_amount,Loss_amount-cum_lost+Recovery_amount,0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Sep 2022 11:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Allocate-Recovery-Amount-Value-to-loss-amount/m-p/835044#M330095</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-09-25T11:02:30Z</dc:date>
    </item>
  </channel>
</rss>

