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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 735 views
  • 0 likes
  • 2 in conversation