<?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: The sum of 3 fixed payments met date within any 1 to 3 consecutive cycle end dates. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/The-sum-of-3-fixed-payments-met-date-within-any-1-to-3/m-p/924186#M363772</link>
    <description>&lt;P&gt;If the data are sorted by acct_no/cyc_no, then the programming is easy with a DATA step.&amp;nbsp; All you need to determine is whether the cyc_no value for the current qualifying obs is no more than two greater than the second prior qualifying obs (and has the same acct_no).&amp;nbsp; By "qualifying" I mean obs with a positive payment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is true then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by acct_no;
  flag=0;
  if fix_paymt&amp;gt;0 then do;
    if lag2(acct_no)=acct_no and lag2(cyc_no)&amp;gt;=cyc_no-2 then flag=1;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 12 Apr 2024 18:38:27 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2024-04-12T18:38:27Z</dc:date>
    <item>
      <title>The sum of 3 fixed payments met date within any 1 to 3 consecutive cycle end dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-sum-of-3-fixed-payments-met-date-within-any-1-to-3/m-p/923887#M363695</link>
      <description>&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;acct_no&lt;/TD&gt;&lt;TD&gt;fix_paymt&lt;/TD&gt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t;5&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;24-Jun&lt;/TD&gt;&lt;TD&gt;25-Jun&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#339966"&gt;&lt;EM&gt;1&lt;/EM&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#339966"&gt;&lt;EM&gt;25-Jun&lt;/EM&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;25-Jul&lt;/TD&gt;&lt;TD&gt;25-Jul&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#339966"&gt;&lt;EM&gt;1&lt;/EM&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#339966"&gt;&lt;EM&gt;25-Jul&lt;/EM&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello - I have thousands of customers' transaction data like the above until the &lt;STRONG&gt;cyc_no&lt;/STRONG&gt; column and I want to get the next two columns:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x3_paymt_met: 3 payments met tag&lt;/P&gt;&lt;P&gt;x3_paymt_met_dt: 3 paymnets met date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What do I need? - Find the first transaction date when a customer made&amp;nbsp;&lt;STRONG&gt;the sum of 3 fixed payments within 1 to 3 consecutive cycle end dates.&amp;nbsp;&lt;/STRONG&gt;(We need to consider the missing (no payment) cycle as well)&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;In the above example, customer 123 first met the criteria on 25 Jun as they paid at least $30 (3 * fixed pay) within 3 consecutive cycles 4,5, and 6.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;The customer didn't meet this criterion in the first 3 cycles 1,2, and 3. Then, we consider the transaction from the next cycle i.e. from 2 to 4.&lt;/LI&gt;&lt;LI&gt;Now, we sum the transactions made in cycles 2 to 4. The customer didn't meet the criteria here either.&lt;/LI&gt;&lt;LI&gt;Similarly,&amp;nbsp;transactions made in cycles 3 to 5.&amp;nbsp;The customer didn't meet the criteria here either.&lt;/LI&gt;&lt;LI&gt;Likewise,&amp;nbsp;transactions made cycles 4 to 6.&amp;nbsp;The customer finally met the criteria here.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Likewise,&amp;nbsp;transactions made in cycles 5 to 7.&amp;nbsp;The customer met the criteria here as well.&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Rules:&lt;/P&gt;&lt;P&gt;Customers can pay any amount like $1, or $2.5 etc&lt;/P&gt;&lt;P&gt;They can make multiple payments within the same cycle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please help me code this in SAS/SQL? I am new to SAS programming and not exactly sure how to loop or is there some way to achieve the outcome w/o using loop?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for making it through to the end!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have so far is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data want;
 set above_example;
 by acct_no;
 %j = 1;
 where cyc_no between &amp;amp;j and &amp;amp;j+2;
 find cumulative sum (cuml);
 if cuml &amp;gt;= 3 * fixed pay then do;
  x3_payments_met = 1;
  x3_payments_met_dt = min(txn_dt); end;
 elif cuml &amp;lt; 3*fixed pay then do;
  x3_payments_met = 0;
 j = j+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2024 00:50:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-sum-of-3-fixed-payments-met-date-within-any-1-to-3/m-p/923887#M363695</guid>
      <dc:creator>analyst007</dc:creator>
      <dc:date>2024-04-11T00:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: The sum of 3 fixed payments met date within any 1 to 3 consecutive cycle end dates.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-sum-of-3-fixed-payments-met-date-within-any-1-to-3/m-p/924186#M363772</link>
      <description>&lt;P&gt;If the data are sorted by acct_no/cyc_no, then the programming is easy with a DATA step.&amp;nbsp; All you need to determine is whether the cyc_no value for the current qualifying obs is no more than two greater than the second prior qualifying obs (and has the same acct_no).&amp;nbsp; By "qualifying" I mean obs with a positive payment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is true then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by acct_no;
  flag=0;
  if fix_paymt&amp;gt;0 then do;
    if lag2(acct_no)=acct_no and lag2(cyc_no)&amp;gt;=cyc_no-2 then flag=1;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2024 18:38:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-sum-of-3-fixed-payments-met-date-within-any-1-to-3/m-p/924186#M363772</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-04-12T18:38:27Z</dc:date>
    </item>
  </channel>
</rss>

