Advertisement
Guest User

Untitled

a guest
Jan 16th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. %macro update(before);
  2. proc sql outobs=5;
  3. CREATE TABLE A.Transaction_Data_Before_&before as
  4. SELECT YEAR(Trans1.date2), MONTH(Trans1.date2),Trans1.account_id, SUM(CASE WHEN type = "PRIJEM" THEN Trans1.amount ELSE 0 END) as credit_sum_&before,
  5. SUM(CASE WHEN type = "VYDAJ" THEN Trans1.amount ELSE 0 END) as withdrawal_sum_&before,
  6. coalesce(sum(type = "PRIJEM"),0) as credit_count_&before,
  7. coalesce(sum(type = "VYDAJ"),0) as withdrawal_count_&before,
  8. (SELECT
  9. MAX(Trans2.balance)
  10. FROM A.TRANS as Trans2
  11. WHERE
  12. Trans2.account_id = Trans1.account_id
  13. AND YEAR(Trans2.date2) = YEAR(INTNX('month',Loan.date2,-&before))
  14. AND MONTH(Trans2.date2) = MONTH(INTNX('month',Loan.date2,-&before))) as balance_end_of_month_&before
  15. FROM A.LOAN as Loan
  16. LEFT JOIN A.Trans as Trans1 ON Loan.account_id = Trans1.account_id
  17. WHERE MONTH(Trans1.date2) = MONTH(INTNX('month',Loan.date2,-&before))
  18. AND YEAR(Trans1.date2) = YEAR(INTNX('month',Loan.date2,-&before))
  19. GROUP BY YEAR(Trans1.date2), MONTH(Trans1.date2), Loan.account_id;
  20. %mend;
  21.  
  22. %update(1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement