Hi @novinosrin the code works good now! The error previously was due to failure of changing 'type' to the real column name . I have studied some Dash document to help me understand your code. do _n_=1 by 1 until(last.account_id);
set tran;
by account_id notsorted;
_amount=ifn(type='credit',amount,-amount);
if type="credit" then h.add();
else if type="debit" then do;
if h.check(key:abs(_amount))=0 then rc=h.removedup(key:abs(_amount));
else h.add(); Then I ran this part only to understand your logic. if you find a credit, you add it to hash table, if you find a debit, you check whether there is a credit or debit already exist, if exist, delete all previous ones with removedup(), if not, add it here? However, the result I get is like this, it doesn't follow my logic. account_id amount type trans_seq _amount rc 000123ab 104.42 debit 2 -104.42 0 001 100 debit 32 -100 0 002 30 credit 1 30 003 50 credit 1 50 004 10 credit 2 10 005 10 debit 3 -10 0 do _n_=1 to _n_;
set tran;
_amount=ifn(type='credit',amount,-amount);
if h.check()=0 then do;
output;
rc=h.removedup(); the second part of your code, you checked the tran table again, but without groupby account_id? if one _amount(credit positive, debit negative) exist already in the previous hash table, then output -- write it to want table? then remove previous record with the same amount? Since it is not grouped by account_id, which means the same amount of different user will works here too. Could you correct me where did I read wrong? since your code works very well. by the way I add this before your code, to make sure that credit always shows first than debit. PROC SORT data=tran;
BY account_id amount type;
RUN;
... View more