BookmarkSubscribeRSS Feed
dash
Obsidian | Level 7

Hi,

I want to compare variable of table1 with table2. If discrepancy found, store it in a new dataset with a comment. After that, compare each variable value from table1 with variable value of table2. If found mismatch, stored in new dataset.

Expected Output

comment  variable missing for table2

length-ename-emp

length-hdate-HR 

label-dname-Dept

 

 

 

data table1;
input dataset $ variable $ label $ datatype $ length $ comment $;
datalines;
Emp ename empname char 40 .
Emp job job char 20 .
Emp sal salary char 20000 .
Dept dname deptname char 10 .
HR hdate hiredate date date9 .
;
run;
data table2;
input dataset $ variable $ label $ datatype $ length $;
datalines;
Emp ename empname char 48
Emp job job char 20
Emp sal salary char 20000
Dept dname dept char 10
HR hdate hiredate date date9.
;
run;
1 REPLY 1
Kurt_Bremser
Super User

Use PROC COMPARE:

proc sort data=table1;
by dataset variable;
run;

proc sort data=table2;
by dataset variable;
run;

proc compare
  base=table1
  compare=table2
  listvar
  out=comp
;
id dataset variable;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1050 views
  • 0 likes
  • 2 in conversation