I need to remove matching credit and debit entries from a dataset what is the easiest way to do this?
HAVE:
LOAN_NBR | INT_AMT_PAID | PRIN_AMT_PAID | EFF_FROM_DT |
60016100 | 20.58 | -98.50 | 07Jan2019 |
60016101 | 29.72 | -80.28 | 07Jan2019 |
60016101 | 15.19 | -94.81 | 28Jan2019 |
60016102 | 52.70 | -57.35 | 16Jan2019 |
60016102 | 0.00 | -110.05 | 16Jan2019 |
60016103 | 121.08 | -235.92 | 04Jan2019 |
60016122 | 41.29 | -89.06 | 17Jan2019 |
60016122 | -41.29 | 89.06 | 24Jan2019 |
60016122 | 57.27 | -73.08 | 29Jan2019 |
60016212 | 29.24 | -73.85 | 09Jan2019 |
60016212 | -29.24 | 73.85 | 17Jan2019 |
60016274 | 142.96 | -186.55 | 11Jan2019 |
60016274 | -142.96 | 186.55 | 21Jan2019 |
60016326 | 45.99 | -96.08 | 03Jan2019 |
60016326 | -45.99 | 96.08 | 08Jan2019 |
60016326 | 57.48 | -84.59 | 10Jan2019 |
60016468 | 61.45 | -113.64 | 31Dec2018 |
60016468 | -61.45 | 113.64 | 31Dec2018 |
60016501 | 17.69 | -80.70 | 15Jan2019 |
60016501 | 18.76 | -79.63 | 17Jan2019 |
60016501 | -17.69 | 80.70 | 17Jan2019 |
60016701 | 18.76 | -81.24 | 08Jan2019 |
60016701 | -18.76 | 81.24 | 14Jan2019 |
60016701 | 26.48 | -73.52 | 22Jan2019 |
60016701 | 3.75 | -96.25 | 29Jan2019 |
60016760 | 24.25 | -102.86 | 31Dec2018 |
60016760 | 5.15 | -121.96 | 07Jan2019 |
60016760 | -5.15 | 121.96 | 14Jan2019 |
60016760 | 13.24 | -113.87 | 18Jan2019 |
60016848 | 32.63 | -77.37 | 21Dec2018 |
60016848 | 50.90 | -55.10 | 04Jan2019 |
60016848 | -32.63 | 77.37 | 04Jan2019 |
60016848 | 18.04 | -87.57 | 18Jan2019 |
WANT:
LOAN_NBR | INT_AMT_PAID | PRIN_AMT_PAID | EFF_FROM_DT |
60016100 | 20.58 | -98.50 | 07Jan2019 |
60016101 | 29.72 | -80.28 | 07Jan2019 |
60016101 | 15.19 | -94.81 | 28Jan2019 |
60016102 | 52.70 | -57.35 | 16Jan2019 |
60016102 | 0.00 | -110.05 | 16Jan2019 |
60016103 | 121.08 | -235.92 | 04Jan2019 |
60016122 | 41.29 | -89.06 | 17Jan2019 |
60016122 | -41.29 | 89.06 | 24Jan2019 |
60016122 | 57.27 | -73.08 | 29Jan2019 |
60016212 | 29.24 | -73.85 | 09Jan2019 |
60016212 | -29.24 | 73.85 | 17Jan2019 |
60016274 | 142.96 | -186.55 | 11Jan2019 |
60016274 | -142.96 | 186.55 | 21Jan2019 |
60016326 | 45.99 | -96.08 | 03Jan2019 |
60016326 | -45.99 | 96.08 | 08Jan2019 |
60016326 | 57.48 | -84.59 | 10Jan2019 |
60016468 | 61.45 | -113.64 | 31Dec2018 |
60016468 | -61.45 | 113.64 | 31Dec2018 |
60016501 | 17.69 | -80.70 | 15Jan2019 |
60016501 | 18.76 | -79.63 | 17Jan2019 |
60016501 | -17.69 | 80.70 | 17Jan2019 |
60016701 | 18.76 | -81.24 | 08Jan2019 |
60016701 | -18.76 | 81.24 | 14Jan2019 |
60016701 | 26 | -73.52 | 43487.00 |
60016701 | 4 | -96.25 | 43494.00 |
60016760 | 24 | -102.86 | 43465.00 |
60016760 | 5.15 | -121.96 | 07Jan2019 |
60016760 | -5.15 | 121.96 | 14Jan2019 |
60016760 | 13.24 | -113.87 | 18Jan2019 |
60016848 | 32.63 | -77.37 | 21Dec2018 |
60016848 | 50.90 | -55.10 | 04Jan2019 |
60016848 | -32.63 | 77.37 | 04Jan2019 |
60016848 | 18.04 | -87.57 | 18Jan2019 |
@novinosrin not all transactions will have reversals
My understanding is you are basically discarding those transactions that are reversed. Is that correct?
if yes, then I am wondering why this one is being discarded in your output
60016848 | 18.04 | -87.57 | 18Jan2019 | 600 |
yes, that transaction should stay. error from my end
There is transaction code. 600 is for normal transaction and 608 is for reversal. if that's what you meant by another identifier
HAVE:
LOAN_NBR | INT_AMT_PAID | PRIN_AMT_PAID | EFF_FROM_DT | TRAN_CODE |
60016100 | 20.58 | -98.50 | 07Jan2019 | 600 |
60016101 | 29.72 | -80.28 | 07Jan2019 | 600 |
60016101 | 15.19 | -94.81 | 28Jan2019 | 600 |
60016102 | 52.70 | -57.35 | 16Jan2019 | 600 |
60016102 | 0.00 | -110.05 | 16Jan2019 | 600 |
60016103 | 121.08 | -235.92 | 04Jan2019 | 600 |
60016122 | 41.29 | -89.06 | 17Jan2019 | 600 |
60016122 | -41.29 | 89.06 | 24Jan2019 | 608 |
60016122 | 57.27 | -73.08 | 29Jan2019 | 600 |
60016212 | 29.24 | -73.85 | 09Jan2019 | 600 |
60016212 | -29.24 | 73.85 | 17Jan2019 | 608 |
60016274 | 142.96 | -186.55 | 11Jan2019 | 600 |
60016274 | -142.96 | 186.55 | 21Jan2019 | 608 |
60016326 | 45.99 | -96.08 | 03Jan2019 | 600 |
60016326 | -45.99 | 96.08 | 08Jan2019 | 608 |
60016326 | 57.48 | -84.59 | 10Jan2019 | 600 |
60016468 | 61.45 | -113.64 | 31Dec2018 | 600 |
60016468 | -61.45 | 113.64 | 31Dec2018 | 608 |
60016501 | 17.69 | -80.70 | 15Jan2019 | 600 |
60016501 | 18.76 | -79.63 | 17Jan2019 | 600 |
60016501 | -17.69 | 80.70 | 17Jan2019 | 608 |
60016701 | 18.76 | -81.24 | 08Jan2019 | 600 |
60016701 | -18.76 | 81.24 | 14Jan2019 | 608 |
60016701 | 26.48 | -73.52 | 22Jan2019 | 600 |
60016701 | 3.75 | -96.25 | 29Jan2019 | 600 |
60016760 | 24.25 | -102.86 | 31Dec2018 | 600 |
60016760 | 5.15 | -121.96 | 07Jan2019 | 600 |
60016760 | -5.15 | 121.96 | 14Jan2019 | 608 |
60016760 | 13.24 | -113.87 | 18Jan2019 | 600 |
60016848 | 32.63 | -77.37 | 21Dec2018 | 600 |
60016848 | 50.90 | -55.10 | 04Jan2019 | 600 |
60016848 | -32.63 | 77.37 | 04Jan2019 | 608 |
60016848 | 18.04 | -87.57 | 18Jan2019 | 600 |
WANT:
LOAN_NBR | INT_AMT_PAID | PRIN_AMT_PAID | EFF_FROM_DT | TRAN_CODE |
60016100 | 20.58 | -98.50 | 07Jan2019 | 600 |
60016101 | 29.72 | -80.28 | 07Jan2019 | 600 |
60016101 | 15.19 | -94.81 | 28Jan2019 | 600 |
60016102 | 52.70 | -57.35 | 16Jan2019 | 600 |
60016102 | 0.00 | -110.05 | 16Jan2019 | 600 |
60016103 | 121.08 | -235.92 | 04Jan2019 | 600 |
60016122 | 41.29 | -89.06 | 17Jan2019 | 600 |
60016122 | -41.29 | 89.06 | 24Jan2019 | 608 |
60016122 | 57.27 | -73.08 | 29Jan2019 | 600 |
60016212 | 29.24 | -73.85 | 09Jan2019 | 600 |
60016212 | -29.24 | 73.85 | 17Jan2019 | 608 |
60016274 | 142.96 | -186.55 | 11Jan2019 | 600 |
60016274 | -142.96 | 186.55 | 21Jan2019 | 608 |
60016326 | 45.99 | -96.08 | 03Jan2019 | 600 |
60016326 | -45.99 | 96.08 | 08Jan2019 | 608 |
60016326 | 57.48 | -84.59 | 10Jan2019 | 600 |
60016468 | 61.45 | -113.64 | 31Dec2018 | 600 |
60016468 | -61.45 | 113.64 | 31Dec2018 | 608 |
60016501 | 17.69 | -80.70 | 15Jan2019 | 600 |
60016501 | 18.76 | -79.63 | 17Jan2019 | 600 |
60016501 | -17.69 | 80.70 | 17Jan2019 | 608 |
60016701 | 18.76 | -81.24 | 08Jan2019 | 600 |
60016701 | -18.76 | 81.24 | 14Jan2019 | 608 |
60016701 | 26 | -73.52 | 43487.00 | 600 |
60016701 | 4 | -96.25 | 43494.00 | 600 |
60016760 | 24 | -102.86 | 43465.00 | 600 |
60016760 | 5.15 | -121.96 | 07Jan2019 | 600 |
60016760 | -5.15 | 121.96 | 14Jan2019 | 608 |
60016760 | 13.24 | -113.87 | 18Jan2019 | 600 |
60016848 | 32.63 | -77.37 | 21Dec2018 | 600 |
60016848 | 50.90 | -55.10 | 04Jan2019 | 600 |
60016848 | -32.63 | 77.37 | 04Jan2019 | 608 |
60016848 | 18.04 | -87.57 | 18Jan2019 | 600 |
Hi @sivakoya see if this helps
data have;
input LOAN_NBR INT_AMT_PAID PRIN_AMT_PAID EFF_FROM_DT :date9.;
format EFF_FROM_DT date9.;
cards;
60016100 20.58 -98.50 07Jan2019
60016101 29.72 -80.28 07Jan2019
60016101 15.19 -94.81 28Jan2019
60016102 52.70 -57.35 16Jan2019
60016102 0.00 -110.05 16Jan2019
60016103 121.08 -235.92 04Jan2019
60016122 41.29 -89.06 17Jan2019
60016122 -41.29 89.06 24Jan2019
60016122 57.27 -73.08 29Jan2019
60016212 29.24 -73.85 09Jan2019
60016212 -29.24 73.85 17Jan2019
60016274 142.96 -186.55 11Jan2019
60016274 -142.96 186.55 21Jan2019
60016326 45.99 -96.08 03Jan2019
60016326 -45.99 96.08 08Jan2019
60016326 57.48 -84.59 10Jan2019
60016468 61.45 -113.64 31Dec2018
60016468 -61.45 113.64 31Dec2018
60016501 17.69 -80.70 15Jan2019
60016501 18.76 -79.63 17Jan2019
60016501 -17.69 80.70 17Jan2019
60016701 18.76 -81.24 08Jan2019
60016701 -18.76 81.24 14Jan2019
60016701 26.48 -73.52 22Jan2019
60016701 3.75 -96.25 29Jan2019
60016760 24.25 -102.86 31Dec2018
60016760 5.15 -121.96 07Jan2019
60016760 -5.15 121.96 14Jan2019
60016760 13.24 -113.87 18Jan2019
60016848 32.63 -77.37 21Dec2018
60016848 50.90 -55.10 04Jan2019
60016848 -32.63 77.37 04Jan2019
60016848 18.04 -87.57 18Jan2019
;
data temp;
set have;
n1=abs(INT_AMT_PAID);
n2=abs(PRIN_AMT_PAID);
run;
proc sort data=temp out=_temp;
by loan_nbr n1 n2 ;
run;
data want;
n=1;
do _n_=1 by 1 until(last.loan_nbr);
set _temp;
by loan_nbr;
array t(9999);
if sum(INT_AMT_PAID,lag(INT_AMT_PAID))=0 and sum(PRIN_AMT_PAID,lag(PRIN_AMT_PAID))=0 then do;
t(n)=_n_-1;
n+1;
t(n)=_n_;
end;
end;
do _n_=1 by 1 until(last.loan_nbr);
set _temp;
by loan_nbr;
if _n_ not in t then output;
end;
drop t: n:;
run;
If you want more robust, I can apply hashes , but we do not know how comfortable you are though, so feel free to let us know
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.