BookmarkSubscribeRSS Feed
sivakoya
Obsidian | Level 7

I need to remove matching credit and debit entries from a dataset what is the easiest way to do this?

HAVE:

LOAN_NBRINT_AMT_PAIDPRIN_AMT_PAIDEFF_FROM_DT
6001610020.58-98.5007Jan2019
6001610129.72-80.2807Jan2019
6001610115.19-94.8128Jan2019
6001610252.70-57.3516Jan2019
600161020.00-110.0516Jan2019
60016103121.08-235.9204Jan2019
6001612241.29-89.0617Jan2019
60016122-41.2989.0624Jan2019
6001612257.27-73.0829Jan2019
6001621229.24-73.8509Jan2019
60016212-29.2473.8517Jan2019
60016274142.96-186.5511Jan2019
60016274-142.96186.5521Jan2019
6001632645.99-96.0803Jan2019
60016326-45.9996.0808Jan2019
6001632657.48-84.5910Jan2019
6001646861.45-113.6431Dec2018
60016468-61.45113.6431Dec2018
6001650117.69-80.7015Jan2019
6001650118.76-79.6317Jan2019
60016501-17.6980.7017Jan2019
6001670118.76-81.2408Jan2019
60016701-18.7681.2414Jan2019
6001670126.48-73.5222Jan2019
600167013.75-96.2529Jan2019
6001676024.25-102.8631Dec2018
600167605.15-121.9607Jan2019
60016760-5.15121.9614Jan2019
6001676013.24-113.8718Jan2019
6001684832.63-77.3721Dec2018
6001684850.90-55.1004Jan2019
60016848-32.6377.3704Jan2019
6001684818.04-87.5718Jan2019

WANT:

LOAN_NBRINT_AMT_PAIDPRIN_AMT_PAIDEFF_FROM_DT
6001610020.58-98.5007Jan2019
6001610129.72-80.2807Jan2019
6001610115.19-94.8128Jan2019
6001610252.70-57.3516Jan2019
600161020.00-110.0516Jan2019
60016103121.08-235.9204Jan2019
6001612241.29-89.0617Jan2019
60016122-41.2989.0624Jan2019
6001612257.27-73.0829Jan2019
6001621229.24-73.8509Jan2019
60016212-29.2473.8517Jan2019
60016274142.96-186.5511Jan2019
60016274-142.96186.5521Jan2019
6001632645.99-96.0803Jan2019
60016326-45.9996.0808Jan2019
6001632657.48-84.5910Jan2019
6001646861.45-113.6431Dec2018
60016468-61.45113.6431Dec2018
6001650117.69-80.7015Jan2019
6001650118.76-79.6317Jan2019
60016501-17.6980.7017Jan2019
6001670118.76-81.2408Jan2019
60016701-18.7681.2414Jan2019
6001670126-73.5243487.00
600167014-96.2543494.00
6001676024-102.8643465.00
600167605.15-121.9607Jan2019
60016760-5.15121.9614Jan2019
6001676013.24-113.8718Jan2019
6001684832.63-77.3721Dec2018
6001684850.90-55.1004Jan2019
60016848-32.6377.3704Jan2019
6001684818.04-87.5718Jan2019
7 REPLIES 7
novinosrin
Tourmaline | Level 20

Hi @sivakoya   Where's the matching credit and debit entry for this?

 

60016848 18.04 -87.57 18Jan2019
sivakoya
Obsidian | Level 7

@novinosrin not all transactions will have reversals

novinosrin
Tourmaline | Level 20

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
sivakoya
Obsidian | Level 7

yes, that transaction should stay. error from my end

Reeza
Super User
You need another identifier to do this properly, otherwise it's a best guess. You don't have any other variables indicating a transactions reversal?
sivakoya
Obsidian | Level 7

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_NBRINT_AMT_PAIDPRIN_AMT_PAIDEFF_FROM_DTTRAN_CODE
6001610020.58-98.5007Jan2019600
6001610129.72-80.2807Jan2019600
6001610115.19-94.8128Jan2019600
6001610252.70-57.3516Jan2019600
600161020.00-110.0516Jan2019600
60016103121.08-235.9204Jan2019600
6001612241.29-89.0617Jan2019600
60016122-41.2989.0624Jan2019608
6001612257.27-73.0829Jan2019600
6001621229.24-73.8509Jan2019600
60016212-29.2473.8517Jan2019608
60016274142.96-186.5511Jan2019600
60016274-142.96186.5521Jan2019608
6001632645.99-96.0803Jan2019600
60016326-45.9996.0808Jan2019608
6001632657.48-84.5910Jan2019600
6001646861.45-113.6431Dec2018600
60016468-61.45113.6431Dec2018608
6001650117.69-80.7015Jan2019600
6001650118.76-79.6317Jan2019600
60016501-17.6980.7017Jan2019608
6001670118.76-81.2408Jan2019600
60016701-18.7681.2414Jan2019608
6001670126.48-73.5222Jan2019600
600167013.75-96.2529Jan2019600
6001676024.25-102.8631Dec2018600
600167605.15-121.9607Jan2019600
60016760-5.15121.9614Jan2019608
6001676013.24-113.8718Jan2019600
6001684832.63-77.3721Dec2018600
6001684850.90-55.1004Jan2019600
60016848-32.6377.3704Jan2019608
6001684818.04-87.5718Jan2019600

 

WANT:

 

LOAN_NBRINT_AMT_PAIDPRIN_AMT_PAIDEFF_FROM_DTTRAN_CODE
6001610020.58-98.5007Jan2019600
6001610129.72-80.2807Jan2019600
6001610115.19-94.8128Jan2019600
6001610252.70-57.3516Jan2019600
600161020.00-110.0516Jan2019600
60016103121.08-235.9204Jan2019600
6001612241.29-89.0617Jan2019600
60016122-41.2989.0624Jan2019608
6001612257.27-73.0829Jan2019600
6001621229.24-73.8509Jan2019600
60016212-29.2473.8517Jan2019608
60016274142.96-186.5511Jan2019600
60016274-142.96186.5521Jan2019608
6001632645.99-96.0803Jan2019600
60016326-45.9996.0808Jan2019608
6001632657.48-84.5910Jan2019600
6001646861.45-113.6431Dec2018600
60016468-61.45113.6431Dec2018608
6001650117.69-80.7015Jan2019600
6001650118.76-79.6317Jan2019600
60016501-17.6980.7017Jan2019608
6001670118.76-81.2408Jan2019600
60016701-18.7681.2414Jan2019608
6001670126-73.5243487.00600
600167014-96.2543494.00600
6001676024-102.8643465.00600
600167605.15-121.9607Jan2019600
60016760-5.15121.9614Jan2019608
6001676013.24-113.8718Jan2019600
6001684832.63-77.3721Dec2018600
6001684850.90-55.1004Jan2019600
60016848-32.6377.3704Jan2019608
6001684818.04-87.5718Jan2019600

 

novinosrin
Tourmaline | Level 20

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 7 replies
  • 1351 views
  • 1 like
  • 3 in conversation