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:
acct | age | payment | type |
A101 | 46 | 1000.5 | car |
A102 | 35 | 438.12 | cooking |
A103 | 27 | 80.6 | cloth |
tableB:
acct | age | payment | type |
A101 | 46 | 1000.55 | car |
A102 | 35 | 438.12 | cloth |
A103 | 27 | 80.4 | cloth |
compare:
acct | same |
A101 | yes |
A102 | no |
A103 | no |
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;
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;
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: