<?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: Logic Help Required in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Logic-Help-Required/m-p/125034#M25568</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code worked pretty well and I had no difficulty. Overall, I have understood what you tried to do, But would you please explain the Balance_1 part because I thought this is calculated before the loop starts but it is calculated dynamically which I could not understand. Please expalin.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks Again&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 27 Oct 2013 14:05:23 GMT</pubDate>
    <dc:creator>bnarang</dc:creator>
    <dc:date>2013-10-27T14:05:23Z</dc:date>
    <item>
      <title>Logic Help Required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-Help-Required/m-p/125032#M25566</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a business problem and I am stuck and not able to drive the solution. Anyone able to help or provide some hints would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Consider the hypothetical example below:&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="341"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" width="64"&gt;Shop&lt;/TD&gt;&lt;TD class="xl63" style="border-left: none;" width="71"&gt;Cust_bal1&lt;/TD&gt;&lt;TD class="xl63" style="border-left: none;" width="71"&gt;Cust_bal2&lt;/TD&gt;&lt;TD class="xl63" style="border-left: none;" width="71"&gt;Cust_bal3&lt;/TD&gt;&lt;TD class="xl63" style="border-left: none;" width="64"&gt;Payments&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;30&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;30&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;25&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;30&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;30&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;30&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;30&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a particular shop, A consumer balance is segmented into three Bal1 bal2 and bal3. Bal1 being the highest priority, Bal2 and Bal3. This is retained across the observation and now the consider the payments are made. The Balances has to be moved in such a way that bal1 should be given highest priority then bal2 and so on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ideally, the output should be like:&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="633"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl65" height="20" width="64"&gt;Shop&lt;/TD&gt;&lt;TD class="xl65" style="border-left: none;" width="71"&gt;Cust_bal1&lt;/TD&gt;&lt;TD class="xl65" style="border-left: none;" width="71"&gt;Cust_bal2&lt;/TD&gt;&lt;TD class="xl65" style="border-left: none;" width="71"&gt;Cust_bal3&lt;/TD&gt;&lt;TD class="xl65" style="border-left: none;" width="64"&gt;Payments&lt;/TD&gt;&lt;TD class="xl65" style="border-left: none;" width="64"&gt;cal_bal1&lt;/TD&gt;&lt;TD class="xl65" style="border-left: none;" width="64"&gt;Cal_bal2&lt;/TD&gt;&lt;TD class="xl65" style="border-left: none;" width="64"&gt;Cal_bal3&lt;/TD&gt;&lt;TD class="xl65" style="border-left: none;" width="100"&gt;Payments_1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;30&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;20&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;10&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;30&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;25&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;25&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;30&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;30&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;45&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;25&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;30&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;30&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl65" height="20" style="border-top: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;30&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;40&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;50&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the end, I would only consider the Payments which were contributed for Bal1 and Bal3 and created a separate column payments_1. I have manually created the example and output in Excel because I could not apply the logic in SAS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you so much for help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 27 Oct 2013 04:57:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-Help-Required/m-p/125032#M25566</guid>
      <dc:creator>bnarang</dc:creator>
      <dc:date>2013-10-27T04:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: Logic Help Required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-Help-Required/m-p/125033#M25567</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; Payment_Order=_n_;&lt;BR /&gt;&amp;nbsp; Customer=1;&lt;BR /&gt;&amp;nbsp; input Shop Cust_bal1 Cust_bal2 Cust_bal3 Payments;&lt;BR /&gt;datalines; &lt;BR /&gt;1 30 40 50 20 &lt;BR /&gt;1 30 40 50 25 &lt;BR /&gt;1 30 40 50 30 &lt;BR /&gt;1 30 40 50 40 &lt;BR /&gt;1 30 40 50 10 &lt;BR /&gt;1 30 40 50 15 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want(drop=_:);&lt;BR /&gt;&amp;nbsp; set have;&lt;BR /&gt;&amp;nbsp; by Shop Customer Payment_Order;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain Cal_bal1 Cal_bal2 Cal_bal3 Payments_1 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array Cal_Bal {*} 8. Cal_bal1 Cal_bal2 Cal_bal3;&lt;BR /&gt;&amp;nbsp; array Cust_bal {*}&amp;nbsp;&amp;nbsp; Cust_bal1 Cust_bal2 Cust_bal3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* initiate Cal_Bal vars for a new customer */&lt;BR /&gt;&amp;nbsp; if first.Customer then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do _i=1 to dim(Cal_Bal);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cal_Bal[_i]=Cust_bal[_i];&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _start=1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; _remainder=Payments;&lt;BR /&gt;&amp;nbsp; _Balance1=sum(cal_bal1,cal_bal3);&lt;BR /&gt;&amp;nbsp; do _i=_start to dim(Cal_Bal);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cal_Bal[_i]=Cal_Bal[_i]-_remainder;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Cal_Bal[_i]&amp;lt;=0 then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _remainder=abs(Cal_Bal[_i]);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cal_Bal[_i]=0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _start+1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else leave;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; Payments_1=_Balance1-sum(cal_bal1,cal_bal3);&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 27 Oct 2013 06:22:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-Help-Required/m-p/125033#M25567</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-10-27T06:22:50Z</dc:date>
    </item>
    <item>
      <title>Re: Logic Help Required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-Help-Required/m-p/125034#M25568</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code worked pretty well and I had no difficulty. Overall, I have understood what you tried to do, But would you please explain the Balance_1 part because I thought this is calculated before the loop starts but it is calculated dynamically which I could not understand. Please expalin.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks Again&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 27 Oct 2013 14:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-Help-Required/m-p/125034#M25568</guid>
      <dc:creator>bnarang</dc:creator>
      <dc:date>2013-10-27T14:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Logic Help Required</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-Help-Required/m-p/125035#M25569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;May be I shouldn't have called it "Balance_1". What it does: I get the sum of cal_bal1 and cal_bal3 BEFORE deducting the new payments (that's done in the loop). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After the new payment has been deducted I simply substract the sum of the new amounts of cal_bal1 and cal_bal3 from "Balance_1". The difference is what you want in "Payments_1".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Payments_1="sum(cal_bal1,cal_bal3) before latest deduction of payment" minus "sum(cal_bal1,cal_bal3) after deduction of latest payment"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Oct 2013 02:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-Help-Required/m-p/125035#M25569</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-10-28T02:16:53Z</dc:date>
    </item>
  </channel>
</rss>

