BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ccnky123
Calcite | Level 5

Now I get two table with same primary key ACCT and they have same column names with same column type.
Anyone has any ideas about SAS macro code that colud compare rows in two tables by primary key.
note:
1.Char columns should be totally equal and numeric columns could be different within 2 decimal places
2.using data step with contents statement is a choice

 

 

tableA:

acctagepaymenttype
A101461000.5car
A10235438.12cooking
A1032780.6

cloth

 

tableB:

acctagepaymenttype
A101461000.55car
A10235438.12cloth
A1032780.4cloth

 

compare:

acctsame
A101yes
A102no
A103no
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

why not PROC COMPARE ?

 

data tablea;
infile cards expandtabs;
input acct$	age	payment	type$;
cards;
A101	46	1000.5	car
A102	35	438.12	cooking
A103	27	80.4	cloth
;

data tableb;
infile cards expandtabs;
input acct$	age	payment	type$;
cards;
A101	46	1000.55	car
A102	35	438.12	cloth
A103	27	80.6	cloth
;

proc compare data=tablea compare=tableb criterion=0.1 method=absolute brief ;
id acct;
run;

View solution in original post

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16
data tablea;
input acct$	age	payment	type$;
cards;
A101	46	1000.5	car
A102	35	438.12	cooking
A103	27	80.4	cloth
;

data tableb;
input acct$	age	payment	type$;
cards;
A101	46	1000.55	car
A102	35	438.12	cloth
A103	27	80.6	cloth
;


proc sql;
create table want as select a.* , case when a.type=b.type and abs(a.payment-b.payment)<0.19 then 'Yes' 
else 'No' end as same 
from tablea as a inner join tableb as b on a.acct=b.acct and a.age=b.age;
quit;
Thanks,
Jag
Ksharp
Super User

why not PROC COMPARE ?

 

data tablea;
infile cards expandtabs;
input acct$	age	payment	type$;
cards;
A101	46	1000.5	car
A102	35	438.12	cooking
A103	27	80.4	cloth
;

data tableb;
infile cards expandtabs;
input acct$	age	payment	type$;
cards;
A101	46	1000.55	car
A102	35	438.12	cloth
A103	27	80.6	cloth
;

proc compare data=tablea compare=tableb criterion=0.1 method=absolute brief ;
id acct;
run;

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
  • 2 replies
  • 1786 views
  • 2 likes
  • 3 in conversation