<?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: Report on Credit/Debit/ Balance Transactions using a First In First Out Approach in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Report-on-Credit-Debit-Balance-Transactions-using-a-First-In/m-p/347969#M22978</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Report on Credit/Debit/ Balance Transactions using a First In First Out Approach

Not tested but it seems to work.

inspired by
https://goo.gl/M7qoKq
https://communities.sas.com/t5/SAS-Enterprise-Guide/Report-on-Credit-Debit-Balance-Transactions-using-a-First-In/m-p/347946


HAVE ( I added customer id and a second sample )
================================================

Up to 40 obs WORK.HAVE total obs=6

Obs    CID     DATE            SOB         CREDIT    DEBIT    BALANCE

 1     A01    12/10/2016    RestaurantA      1000         0      1000
 2     A01    12/15/2016    RestaurantB      1500         0      2500
 3     A01    12/20/2016    ------------        0      1500      1000
 4     A02    12/10/2016    RestaurantA      1000         0      1000
 5     A02    12/15/2016    RestaurantB      1500         0      2500
 6     A02    12/20/2016    ------------        0      2500         0

WANT
====

Up to 40 obs WORK.WANT total obs=4

                                                    REDEMTION_
Obs    CID     DATE             SOB        CREDIT      PCT

 1     A01    12/10/2016    RestaurantA     1000     100.000  1500 debit ( 1000 credit  - 1500 debit = 1005 redeemed
 2     A01    12/15/2016    RestaurantB     1500      33.333   500/1500 = 33% redemption percent

 3     A02    12/10/2016    RestaurantA     1000     100.000
 4     A02    12/15/2016    RestaurantB     1500     100.000

*                _                  _       _
 _ __ ___   __ _| | _____        __| | __ _| |_ __ _
| '_ ` _ \ / _` | |/ / _ \_____ / _` |/ _` | __/ _` |
| | | | | | (_| |   &amp;lt;  __/_____| (_| | (_| | || (_| |
|_| |_| |_|\__,_|_|\_\___|      \__,_|\__,_|\__\__,_|

;

data have;
informat cid $4. date mmddyy10. sob $24. credit debit balance comma12.;
INPUT cid date SOB Credit Debit Balance;
cards4;
A01 12/10/2016 RestaurantA 1,000 0 1,000 .
A01 12/15/2016 RestaurantB 1,500 0 2,500 .
A01 12/20/2016 ------------ 0 1,500 1,000
A02 12/10/2016 RestaurantA 1,000 0 1,000 .
A02 12/15/2016 RestaurantB 1,500 0 2,500 .
A02 12/20/2016 ------------ 0 2,500 0
;;;;
run;quit;

*          _       _   _
 ___  ___ | |_   _| |_(_) ___  _ __
/ __|/ _ \| | | | | __| |/ _ \| '_ \
\__ \ (_) | | |_| | |_| | (_) | | | |
|___/\___/|_|\__,_|\__|_|\___/|_| |_|

;

data want(where=(not (sob=:'------')));
  retain debit_next debit_keep  dif 0;
  do until(last.cid);
    set have;
    by cid;
    debit_keep=debit_keep + debit;
  end;
  debit_next=debit_keep;
  do until(last.cid);
    set have;
    by cid;
    dif=credit - debit_next;
    if dif &amp;lt;= 0 then do;
         debit_next=abs(dif);
         redemtion_pct=100;
    end;
    else do;
       redemtion_pct=100*debit_next/credit;
    end;
    keep cid date sob  credit redemtion_pct;
    output;
  end;
  debit_next=0;
  debit_keep=0;
  dif=0;
run;quit;

/*
NOTE: There were 6 observations read from the data set WORK.HAVE.
NOTE: There were 6 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 4 observations and 5 variables.
NOTE: DATA statement used (Total process time):
*/


&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 07 Apr 2017 01:16:47 GMT</pubDate>
    <dc:creator>rogerjdeangelis</dc:creator>
    <dc:date>2017-04-07T01:16:47Z</dc:date>
    <item>
      <title>Report on Credit/Debit/ Balance Transactions using a First In First Out Approach</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Report-on-Credit-Debit-Balance-Transactions-using-a-First-In/m-p/347946#M22974</link>
      <description>&lt;P&gt;Good Afternoon,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to draft a reward redemption project on sas eg and I am facing some difficulties.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently I have 2 Tables:&lt;/P&gt;&lt;P&gt;- The first one contains the following information:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;MembershipID&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;Credit (in rewards points)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;Rewards Issued Date&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;Source Of Business (Restaurant A, Restaurant B ...)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- The second one contains the following inofrmation:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;MembershipID&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;Debit (in rewards point)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;Redemption Date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to apply a FIFO approach to measure the points redemption by Source of Business based on the dates the points are redeemed. For example, if I start with a zero point balance and I am issued 1,000 points at Restaurant A on 12/10/2016 and 1,500 points at Restaurant B on 12/15/2016; my running balance as of 12/15/2016 becomes 2,500 - let's say now that I redeem 1,500 points on 12/20/2016, I want my query to show a 1,000 deduction from my first credit transaction (Restaurant A) then 500 from second credit transaction (Restaurant B) so that my SOB Redemption Report shows 100%&amp;nbsp;&lt;SPAN&gt;from Restaurant A and&amp;nbsp;33% from Restaurant B&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;INPUT&lt;/STRONG&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;STRONG&gt;&lt;U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; SOB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Credit &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Debit &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Balance&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;12/10/2016 &amp;nbsp; &amp;nbsp;Restaurant A &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,000 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1,000&amp;nbsp;&lt;/P&gt;&lt;P&gt;12/15/2016 &amp;nbsp; &amp;nbsp;Restaurant B &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,500 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2,500&lt;/P&gt;&lt;P&gt;12/20/2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;------------ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,500 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1,000&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;OUTPUT&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;U&gt;&lt;STRONG&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SOB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Redemption%&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;12/20/2016 &amp;nbsp; &amp;nbsp; Restaurant A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100%&amp;nbsp;&lt;/P&gt;&lt;P&gt;12/20/2016 &amp;nbsp; &amp;nbsp; Restaurant B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;33%&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 22:02:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Report-on-Credit-Debit-Balance-Transactions-using-a-First-In/m-p/347946#M22974</guid>
      <dc:creator>chrisjab</dc:creator>
      <dc:date>2017-04-06T22:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Report on Credit/Debit/ Balance Transactions using a First In First Out Approach</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Report-on-Credit-Debit-Balance-Transactions-using-a-First-In/m-p/347951#M22976</link>
      <description>&lt;P&gt;The redemption on 20th doesn't show a company name? Is that on purpose or because you didn't want to type it out?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post some a larger sample data as well as the expected output.&lt;/P&gt;
&lt;P&gt;Make sure to include all your 'edge' cases.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 22:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Report-on-Credit-Debit-Balance-Transactions-using-a-First-In/m-p/347951#M22976</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-06T22:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: Report on Credit/Debit/ Balance Transactions using a First In First Out Approach</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Report-on-Credit-Debit-Balance-Transactions-using-a-First-In/m-p/347969#M22978</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Report on Credit/Debit/ Balance Transactions using a First In First Out Approach

Not tested but it seems to work.

inspired by
https://goo.gl/M7qoKq
https://communities.sas.com/t5/SAS-Enterprise-Guide/Report-on-Credit-Debit-Balance-Transactions-using-a-First-In/m-p/347946


HAVE ( I added customer id and a second sample )
================================================

Up to 40 obs WORK.HAVE total obs=6

Obs    CID     DATE            SOB         CREDIT    DEBIT    BALANCE

 1     A01    12/10/2016    RestaurantA      1000         0      1000
 2     A01    12/15/2016    RestaurantB      1500         0      2500
 3     A01    12/20/2016    ------------        0      1500      1000
 4     A02    12/10/2016    RestaurantA      1000         0      1000
 5     A02    12/15/2016    RestaurantB      1500         0      2500
 6     A02    12/20/2016    ------------        0      2500         0

WANT
====

Up to 40 obs WORK.WANT total obs=4

                                                    REDEMTION_
Obs    CID     DATE             SOB        CREDIT      PCT

 1     A01    12/10/2016    RestaurantA     1000     100.000  1500 debit ( 1000 credit  - 1500 debit = 1005 redeemed
 2     A01    12/15/2016    RestaurantB     1500      33.333   500/1500 = 33% redemption percent

 3     A02    12/10/2016    RestaurantA     1000     100.000
 4     A02    12/15/2016    RestaurantB     1500     100.000

*                _                  _       _
 _ __ ___   __ _| | _____        __| | __ _| |_ __ _
| '_ ` _ \ / _` | |/ / _ \_____ / _` |/ _` | __/ _` |
| | | | | | (_| |   &amp;lt;  __/_____| (_| | (_| | || (_| |
|_| |_| |_|\__,_|_|\_\___|      \__,_|\__,_|\__\__,_|

;

data have;
informat cid $4. date mmddyy10. sob $24. credit debit balance comma12.;
INPUT cid date SOB Credit Debit Balance;
cards4;
A01 12/10/2016 RestaurantA 1,000 0 1,000 .
A01 12/15/2016 RestaurantB 1,500 0 2,500 .
A01 12/20/2016 ------------ 0 1,500 1,000
A02 12/10/2016 RestaurantA 1,000 0 1,000 .
A02 12/15/2016 RestaurantB 1,500 0 2,500 .
A02 12/20/2016 ------------ 0 2,500 0
;;;;
run;quit;

*          _       _   _
 ___  ___ | |_   _| |_(_) ___  _ __
/ __|/ _ \| | | | | __| |/ _ \| '_ \
\__ \ (_) | | |_| | |_| | (_) | | | |
|___/\___/|_|\__,_|\__|_|\___/|_| |_|

;

data want(where=(not (sob=:'------')));
  retain debit_next debit_keep  dif 0;
  do until(last.cid);
    set have;
    by cid;
    debit_keep=debit_keep + debit;
  end;
  debit_next=debit_keep;
  do until(last.cid);
    set have;
    by cid;
    dif=credit - debit_next;
    if dif &amp;lt;= 0 then do;
         debit_next=abs(dif);
         redemtion_pct=100;
    end;
    else do;
       redemtion_pct=100*debit_next/credit;
    end;
    keep cid date sob  credit redemtion_pct;
    output;
  end;
  debit_next=0;
  debit_keep=0;
  dif=0;
run;quit;

/*
NOTE: There were 6 observations read from the data set WORK.HAVE.
NOTE: There were 6 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 4 observations and 5 variables.
NOTE: DATA statement used (Total process time):
*/


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Apr 2017 01:16:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Report-on-Credit-Debit-Balance-Transactions-using-a-First-In/m-p/347969#M22978</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-04-07T01:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Report on Credit/Debit/ Balance Transactions using a First In First Out Approach</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Report-on-Credit-Debit-Balance-Transactions-using-a-First-In/m-p/348078#M22982</link>
      <description>&lt;P&gt;Thank you Roger, I will try it this morning &amp;nbsp;and keep you posted&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 13:23:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Report-on-Credit-Debit-Balance-Transactions-using-a-First-In/m-p/348078#M22982</guid>
      <dc:creator>chrisjab</dc:creator>
      <dc:date>2017-04-07T13:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Report on Credit/Debit/ Balance Transactions using a First In First Out Approach</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Report-on-Credit-Debit-Balance-Transactions-using-a-First-In/m-p/348300#M22989</link>
      <description>&lt;P&gt;Reeza, the rewards points can be redeemed anywhere; however, they are issued at the restaurants - We want to calculate the redemption rate based on where the rewards are issued&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 20:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Report-on-Credit-Debit-Balance-Transactions-using-a-First-In/m-p/348300#M22989</guid>
      <dc:creator>chrisjab</dc:creator>
      <dc:date>2017-04-07T20:49:41Z</dc:date>
    </item>
  </channel>
</rss>

