I have two datasets:
data one;
input id acctype$ catalogtype$ amount;
datalines;
1 credit issued 10
1 credit refund 5
1 credit cancelled 20
2 debit issued 20
2 debit refund 20
3 cash issued 20
run;
data two;
input id acctype$ catalogtype$ amount;
datalines;
1 credit issued 10
1 credit refund 10
1 credit cancelled 10
2 debit issued 20
2 debit refund 10
4 cash refund 10
run;
I want a output that should get matched records from left table, and non matching records from right table like this:
1 credit issued 10 matched
1 credit refund 5 not-matched
1 credit cancelled not-matched
2 debit issued 20 matched
2 debit refund 20 not-matched
3 cash issued 20 not-matched
I want this specifically using proc sql, please. I tried left outer join and union all of both datasets but not able to get solution.
proc sql;
create table WANT as
select A.*,
case when B.ID is not null then "Matched" else "UnMatched" end as RES
from ONE A
left join TWO B
on A.ID=B.ID
and A.ACCTYPE=B.ACCTYPE
and A.CATALOGTYPE=B.CATALOGTYPE
and A.AMOUNT=B.AMOUNT;
quit;
Not tested, but that should work.
proc sql;
create table WANT as
select A.*,
case when B.ID is not null then "Matched" else "UnMatched" end as RES
from ONE A
left join TWO B
on A.ID=B.ID
and A.ACCTYPE=B.ACCTYPE
and A.CATALOGTYPE=B.CATALOGTYPE
and A.AMOUNT=B.AMOUNT;
quit;
Not tested, but that should work.
Yes. This worked. I was joining using only id and hence wasnt getting the solution as I wanted.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.