BookmarkSubscribeRSS Feed
rohithverma
Obsidian | Level 7

i have input data like as mentioned below . i  want to filter the matched debit and credit observations into one dataset and the discrepent one into another dataset.

 

input

 

sno DEBIT CREDIT CHEQUEID VDATE
1 200 0 1234 1-Jan-20
2 200 0 1234 1-Jan-20
3 0 200 1234 2-Jan-20
4 400 0 4567 1-Jan-20
5 400 0 4567 1-Jan-20
6 400 0 4567 1-Jan-20
7 0 400 4567 2-Jan-20
8 600 0 6789 1-Jan-20

 

The output should be

table 1 output 

sno DEBIT CREDIT CHEQUEID VDATE FLAG
2 200 0 1234 1-Jan-20 MATCHED
3 0 200 1234 2-Jan-20 MATCHED
6 400 0 4567 1-Jan-20 MATCHED
7 0 400 4567 2-Jan-20

MATCHED

 

 

 

table 2 output 

 

sno DEBIT CREDIT CHEQUEID VDATE
1 200 0 1234 1-Jan-20
4 400 0 4567 1-Jan-20
5 400 0 4567 1-Jan-20
7 600 0 6789 1-Jan-20
3 REPLIES 3
Ksharp
Super User
data have;
infile cards expandtabs truncover;
input sno 	DEBIT 	CREDIT 	CHEQUEID 	VDATE $20.;
cards;
1 	200 	0 	1234 	1-Jan-20
2 	200 	0 	1234 	1-Jan-20
3 	0 	200 	1234 	2-Jan-20
4 	400 	0 	4567 	1-Jan-20
5 	400 	0 	4567 	1-Jan-20
6 	400 	0 	4567 	1-Jan-20
7 	0 	400 	4567 	2-Jan-20
8 	600 	0 	6789 	1-Jan-20
;

data debit;
 set have;
 if debit ne 0;
 drop credit;
run;
data credit;
 set have;
 if credit ne 0;
 drop debit;
run;
data temp1;
 ina=0;inb=0;
 merge debit(in=ina) credit(in=inb rename=(
 credit=debit sno=_sno vdate=_vdate));
 by debit CHEQUEID;
 if ina and inb then output ;
 run;
data want1;
 set temp1;
 credit=0;output;
 credit=debit;debit=0;sno=_sno;vdate=_vdate;output;
 drop _: ;
run;
proc sql;
create table want2 as
select * from have
 where sno not in (select sno from want1);
quit;

rohithverma
Obsidian | Level 7

NO, here you are creating a duplicate observations

Ksharp
Super User

Here is what I get .

Isn't it what you are looking for ?

x.PNG

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 359 views
  • 0 likes
  • 2 in conversation