BookmarkSubscribeRSS Feed
analyst007
Calcite | Level 5
acct_nofix_paymttxn_amttxn_dtcyc_endcyc_nox3_paymt_metx3_paymt_met_dt
123101024-Jan25-Jan10.
123101024-Feb25-Feb20.
123101027-Apr25-May50.
123101028-Apr25-May50.
123101024-Jun25-Jun6125-Jun
123101025-Jul25-Jul7125-Jul

 

Hello - I have thousands of customers' transaction data like the above until the cyc_no column and I want to get the next two columns:

 

x3_paymt_met: 3 payments met tag

x3_paymt_met_dt: 3 paymnets met date

 

What do I need? - Find the first transaction date when a customer made the sum of 3 fixed payments within 1 to 3 consecutive cycle end dates. (We need to consider the missing (no payment) cycle as well)

  1. 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. 
  2. 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.
  3. Now, we sum the transactions made in cycles 2 to 4. The customer didn't meet the criteria here either.
  4. Similarly, transactions made in cycles 3 to 5. The customer didn't meet the criteria here either.
  5. Likewise, transactions made cycles 4 to 6. The customer finally met the criteria here. 
  6. Likewise, transactions made in cycles 5 to 7. The customer met the criteria here as well. 

Rules:

Customers can pay any amount like $1, or $2.5 etc

They can make multiple payments within the same cycle.

 

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?

 

Thank you so much for making it through to the end!

 

What I have so far is:

data want;
 set above_example;
 by acct_no;
 %j = 1;
 where cyc_no between &j and &j+2;
 find cumulative sum (cuml);
 if cuml >= 3 * fixed pay then do;
  x3_payments_met = 1;
  x3_payments_met_dt = min(txn_dt); end;
 elif cuml < 3*fixed pay then do;
  x3_payments_met = 0;
 j = j+1;
run;

 

 

 

1 REPLY 1
mkeintz
PROC Star

If the data are sorted by acct_no/cyc_no, then the programming is easy with a DATA step.  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).  By "qualifying" I mean obs with a positive payment.

 

If this is true then:

 

data want;
  set have;
  by acct_no;
  flag=0;
  if fix_paymt>0 then do;
    if lag2(acct_no)=acct_no and lag2(cyc_no)>=cyc_no-2 then flag=1;
  end;
run;

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 134 views
  • 0 likes
  • 2 in conversation