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;
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;
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!
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.