In this example, PROC COMPARE compares only the observations that have
matching values for the ID variable.
|
libname proclib 'SAS-library'; |
|
options nodate pageno=1 linesize=80 pagesize=40; |
|
data proclib.emp95;
input #1 idnum $4. @6 name $15.
#2 address $42.
#3 salary 6.;
datalines;
2388 James Schmidt
100 Apt. C Blount St. SW Raleigh NC 27693
92100
2457 Fred Williams
99 West Lane Garner NC 27509
33190
... more data lines...
3888 Kim Siu
5662 Magnolia Blvd Southeast Cary NC 27513
77558
;
data proclib.emp96;
input #1 idnum $4. @6 name $15.
#2 address $42.
#3 salary 6.;
datalines;
2388 James Schmidt
100 Apt. C Blount St. SW Raleigh NC 27693
92100
2457 Fred Williams
99 West Lane Garner NC 27509
33190
...more data lines...
6544 Roger Monday
3004 Crepe Myrtle Court Raleigh NC 27604
47007
; |
|
proc sort data=proclib.emp95 out=emp95_byidnum;
by idnum;
run;
proc sort data=proclib.emp96 out=emp96_byidnum;
by idnum;
run; |
|
proc compare base=emp95_byidnum compare=emp96_byidnum;
id idnum;
title 'Comparing Observations that Have Matching IDNUMs';
run; |
|
Comparing Observations that Have Matching IDNUMs 1
COMPARE Procedure
Comparison of WORK.EMP95_BYIDNUM with WORK.EMP96_BYIDNUM
(Method=EXACT)
Data Set Summary
Dataset Created Modified NVar NObs
WORK.EMP95_BYIDNUM 13MAY98:16:03:36 13MAY98:16:03:36 4 10
WORK.EMP96_BYIDNUM 13MAY98:16:03:36 13MAY98:16:03:36 4 12
Variables Summary
Number of Variables in Common: 4.
Number of ID Variables: 1.
Observation Summary
Observation Base Compare ID
First Obs 1 1 idnum=0987
First Unequal 1 1 idnum=0987
Last Unequal 10 12 idnum=9857
Last Obs 10 12 idnum=9857
Number of Observations in Common: 10.
Number of Observations in WORK.EMP96_BYIDNUM but not in WORK.EMP95_BYIDNUM: 2.
Total Number of Observations Read from WORK.EMP95_BYIDNUM: 10.
Total Number of Observations Read from WORK.EMP96_BYIDNUM: 12.
Number of Observations with Some Compared Variables Unequal: 5.
Number of Observations with All Compared Variables Equal: 5.
Comparing Observations that Have Matching IDNUMs 2
COMPARE Procedure
Comparison of WORK.EMP95_BYIDNUM with WORK.EMP96_BYIDNUM
(Method=EXACT)
Values Comparison Summary
Number of Variables Compared with All Observations Equal: 1.
Number of Variables Compared with Some Observations Unequal: 2.
Total Number of Values which Compare Unequal: 8.
Maximum Difference: 2400.
Variables with Unequal Values
Variable Type Len Ndif MaxDif
address CHAR 42 4
salary NUM 8 4 2400
Value Comparison Results for Variables
_______________________________________________________
|| Base Value Compare Value
idnum || address address
_____ || ___________________+ ___________________+
||
0987 || 2344 Persimmons Bran 2344 Persimmons Bran
2776 || 12988 Wellington Far 12988 Wellington Far
3888 || 5662 Magnolia Blvd S 5662 Magnolia Blvd S
9857 || 1000 Taft Ave. Morri 100 Taft Ave. Morris
_______________________________________________________
Comparing Observations that Have Matching IDNUMs 3
COMPARE Procedure
Comparison of WORK.EMP95_BYIDNUM with WORK.EMP96_BYIDNUM
(Method=EXACT)
Value Comparison Results for Variables
_______________________________________________________
|| Base Compare
idnum || salary salary Diff. % Diff
_____ || _________ _________ _________ _________
||
0987 || 44010 45110 1100 2.4994
3286 || 87734 89834 2100 2.3936
3888 || 77558 79958 2400 3.0945
9857 || 38756 40456 1700 4.3864
_______________________________________________________
| |
|
|
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.