I am new to SAS and trying to solve the following scenario:
Scenario: A loan (123) has more than 2 transactions on a given transaction date. And, each record has a columns: ID, Trans_Amt, LoanNo, etc.
I was asked to create a column to show if two different records with same loan# and ID adds up to 0 for Trans_Amt then those two records should be shown as 'Y'
data have;
input ID$ Loan_No Trans_Am;
datalines;
A1 123 -10
B1 123 20
A1 123 10
A1 123 20
;
run;
Output should be:
data want;
input ID$ Loan_No Trans_Am Exception$;
datalines;
A1 123 -10 Y
B1 123 20 N
A1 123 10 Y
A1 123 20 N
;
run;
Thanks in advance for your help
My thought process is to create loops for ID, LoanNo and iterate through them but unsure as to how to do it in SAS.
A
SETstatement is used to loop through a data set.What if you have transaction amounts -10, 6, 4? Would three records by flagged? Do they have to be 'in-order' to sum to zero? -10, 20, 10 has one pair of record that sum to zero but they are not in order.
You can add an ordering variable, then sort and by loan id and do your sum rules.
Example:
Tell boss very bad idea to have same loan # for different id.
rownumis temporarily added to data set to maintain original order so rule can be performed. Things can become way complicated if someone overpays or takes out more against loan_num or does smaller partial payments.Double DOW loops coded to compute metric for group of contiguous rows within larger group.