Sample 25344: Comparison of two data sets using PROC COMPARE
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample is from the SAS Sample Library. For additional information refer to SAS Help and Online Documentation.
/****************************************************************/
/* S A S S A M P L E L I B R A R Y */
/* */
/* NAME: COMPARE */
/* TITLE: Comparison of Two Data Sets Using PROC COMPARE */
/* PRODUCT: SAS */
/* SYSTEM: ALL */
/* KEYS: DATA MANAGEMENT, */
/* PROCS: COMPARE */
/* DATA: */
/* */
/* SUPPORT: UPDATE: */
/* REF: */
/* MISC: */
/* */
/****************************************************************/
DATA ONE;
DO R=1 TO 4;
DO S=1 TO 20;
T = RANUNI(111111);
U = ARCOS(T);
OUTPUT;
END;
END;
RUN;
PROC PRINT DATA=ONE;
TITLE 'DATA SET ONE';
RUN;
DATA TWO;
SET ONE;
IF R=1 THEN DELETE;
IF S=1 THEN S=0;
IF S=10 THEN DELETE;
IF S=20 THEN S=10;
IF S>15 & S<20 THEN T = T+1;
IF U<T THEN U = 0;
RUN;
PROC PRINT DATA=TWO;
TITLE 'DATA SET TWO';
RUN;
PROC COMPARE DATA=ONE C=TWO OUTNOEQUAL OUT=OUT ALLOBS;
TITLE;
BY R;
RUN;
PROC PRINT DATA=OUT;
TITLE 'DATA SET OUT';
ID R S;
RUN;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
DATA SET ONE
Obs R S T U
1 1 1 0.37610 1.18522
2 1 2 0.52728 1.01539
3 1 3 0.87847 0.49814
4 1 4 0.04289 1.52790
5 1 5 0.18403 1.38571
6 1 6 0.37561 1.18574
7 1 7 0.95891 0.28767
8 1 8 0.79901 0.64514
9 1 9 0.66405 0.84458
10 1 10 0.27611 1.29105
11 1 11 0.30570 1.26013
12 1 12 0.77751 0.68010
13 1 13 0.49527 1.05265
14 1 14 0.94551 0.33163
15 1 15 0.87784 0.49946
16 1 16 0.51855 1.02564
17 1 17 0.16849 1.40149
18 1 18 0.77122 0.69004
19 1 19 0.32063 1.24440
20 1 20 0.47689 1.07368
21 2 1 0.65134 0.86145
22 2 2 0.60595 0.91984
23 2 3 0.50602 1.04024
24 2 4 0.92483 0.39020
25 2 5 0.42547 1.13131
26 2 6 0.34800 1.21536
27 2 7 0.60933 0.91559
28 2 8 0.00877 1.56203
29 2 9 0.21598 1.35310
30 2 10 0.33246 1.23188
31 2 11 0.98128 0.19378
32 2 12 0.22476 1.34410
33 2 13 0.07364 1.49709
34 2 14 0.45785 1.09522
35 2 15 0.74981 0.72302
36 2 16 0.72768 0.75587
37 2 17 0.11582 1.45472
38 2 18 0.07813 1.49258
39 2 19 0.78541 0.66744
40 2 20 0.46477 1.08743
41 3 1 0.88183 0.49107
42 3 2 0.33507 1.22912
43 3 3 0.80385 0.63705
44 3 4 0.98099 0.19531
45 3 5 0.21449 1.35462
46 3 6 0.09990 1.47073
47 3 7 0.06759 1.50316
48 3 8 0.34731 1.21610
49 3 9 0.04129 1.52949
50 3 10 0.79226 0.65629
51 3 11 0.28929 1.27732
52 3 12 0.81403 0.61974
53 3 13 0.80642 0.63272
54 3 14 0.73813 0.74050
55 3 15 0.36671 1.19533
56 3 16 0.54905 0.98957
57 3 17 0.73320 0.74779
58 3 18 0.58023 0.95179
59 3 19 0.97381 0.22938
60 3 20 0.22206 1.34687
61 4 1 0.40495 1.15387
62 4 2 0.66300 0.84597
63 4 3 0.58865 0.94141
64 4 4 0.68480 0.81647
65 4 5 0.18505 1.38468
66 4 6 0.73618 0.74339
67 4 7 0.14178 1.42854
68 4 8 0.88574 0.48272
69 4 9 0.73771 0.74113
70 4 10 0.54161 0.99845
71 4 11 0.39932 1.16002
72 4 12 0.32264 1.24228
73 4 13 0.24074 1.32767
74 4 14 0.78583 0.66676
75 4 15 0.60844 0.91671
76 4 16 0.24102 1.32738
77 4 17 0.41241 1.14570
78 4 18 0.68927 0.81031
79 4 19 0.10690 1.46369
80 4 20 0.04745 1.52333
DATA SET TWO
Obs R S T U
1 2 0 0.65134 0.86145
2 2 2 0.60595 0.91984
3 2 3 0.50602 1.04024
4 2 4 0.92483 0.00000
5 2 5 0.42547 1.13131
6 2 6 0.34800 1.21536
7 2 7 0.60933 0.91559
8 2 8 0.00877 1.56203
9 2 9 0.21598 1.35310
10 2 11 0.98128 0.00000
11 2 12 0.22476 1.34410
12 2 13 0.07364 1.49709
13 2 14 0.45785 1.09522
14 2 15 0.74981 0.00000
15 2 16 1.72768 0.00000
16 2 17 1.11582 1.45472
17 2 18 1.07813 1.49258
18 2 19 1.78541 0.00000
19 2 10 0.46477 1.08743
20 3 0 0.88183 0.00000
21 3 2 0.33507 1.22912
22 3 3 0.80385 0.00000
23 3 4 0.98099 0.00000
24 3 5 0.21449 1.35462
25 3 6 0.09990 1.47073
26 3 7 0.06759 1.50316
27 3 8 0.34731 1.21610
28 3 9 0.04129 1.52949
29 3 11 0.28929 1.27732
30 3 12 0.81403 0.00000
31 3 13 0.80642 0.00000
32 3 14 0.73813 0.74050
33 3 15 0.36671 1.19533
34 3 16 1.54905 0.00000
35 3 17 1.73320 0.00000
36 3 18 1.58023 0.00000
37 3 19 1.97381 0.00000
38 3 10 0.22206 1.34687
39 4 0 0.40495 1.15387
40 4 2 0.66300 0.84597
41 4 3 0.58865 0.94141
42 4 4 0.68480 0.81647
43 4 5 0.18505 1.38468
44 4 6 0.73618 0.74339
45 4 7 0.14178 1.42854
46 4 8 0.88574 0.00000
47 4 9 0.73771 0.74113
48 4 11 0.39932 1.16002
49 4 12 0.32264 1.24228
50 4 13 0.24074 1.32767
51 4 14 0.78583 0.00000
52 4 15 0.60844 0.91671
53 4 16 1.24102 1.32738
54 4 17 1.41241 0.00000
55 4 18 1.68927 0.00000
56 4 19 1.10690 1.46369
57 4 10 0.047447 1.52333
The COMPARE Procedure
Comparison of WORK.ONE with WORK.TWO
(Method=EXACT)
Data Set Summary
Dataset Created Modified NVar NObs
WORK.ONE 01JUL05:15:00:59 01JUL05:15:00:59 4 80
WORK.TWO 01JUL05:15:00:59 01JUL05:15:00:59 4 57
Variables Summary
Number of Variables in Common: 4.
Number of BY Variables: 1.
The COMPARE Procedure
Comparison of WORK.ONE with WORK.TWO
(Method=EXACT)
R=2
Observation Summary
Observation Base Compare
First Obs 21 1
First Unequal 21 1
Last Unequal 39 19
Last Match 39 19
Last Obs 40
Number of Observations in Common: 19.
Number of Observations in WORK.ONE but not in WORK.TWO: 1.
Total Number of Observations Read from WORK.ONE: 20.
Total Number of Observations Read from WORK.TWO: 19.
Number of Observations with Some Compared Variables Unequal: 12.
Number of Observations with All Compared Variables Equal: 7.
Values Comparison Summary
Number of Variables Compared with All Observations Equal: 0.
Number of Variables Compared with Some Observations Unequal: 3.
Total Number of Values which Compare Unequal: 32.
Maximum Difference: 9.
All Variables Compared have Unequal Values
Variable Type Len Ndif MaxDif
S NUM 8 11 9.000
T NUM 8 10 1.707
U NUM 8 11 1.493
Value Comparison Results for Variables
__________________________________________________________
|| Base Compare
Obs || S S Diff. % Diff
________ || _________ _________ _________ _________
||
21 || 1.0000 0 -1.0000 -100.0000
22 || 2.0000 2.0000 0 0
23 || 3.0000 3.0000 0 0
24 || 4.0000 4.0000 0 0
25 || 5.0000 5.0000 0 0
26 || 6.0000 6.0000 0 0
27 || 7.0000 7.0000 0 0
28 || 8.0000 8.0000 0 0
29 || 9.0000 9.0000 0 0
The COMPARE Procedure
Comparison of WORK.ONE with WORK.TWO
(Method=EXACT)
R=2
Value Comparison Results for Variables
__________________________________________________________
|| Base Compare
Obs || S S Diff. % Diff
________ || _________ _________ _________ _________
||
30 || 10.0000 11.0000 1.0000 10.0000
31 || 11.0000 12.0000 1.0000 9.0909
32 || 12.0000 13.0000 1.0000 8.3333
33 || 13.0000 14.0000 1.0000 7.6923
34 || 14.0000 15.0000 1.0000 7.1429
35 || 15.0000 16.0000 1.0000 6.6667
36 || 16.0000 17.0000 1.0000 6.2500
37 || 17.0000 18.0000 1.0000 5.8824
38 || 18.0000 19.0000 1.0000 5.5556
39 || 19.0000 10.0000 -9.0000 -47.3684
__________________________________________________________
__________________________________________________________
|| Base Compare
Obs || T T Diff. % Diff
________ || _________ _________ _________ _________
||
21 || 0.6513 0.6513 0 0
22 || 0.6060 0.6060 0 0
23 || 0.5060 0.5060 0 0
24 || 0.9248 0.9248 0 0
25 || 0.4255 0.4255 0 0
26 || 0.3480 0.3480 0 0
27 || 0.6093 0.6093 0 0
28 || 0.008766 0.008766 0 0
29 || 0.2160 0.2160 0 0
30 || 0.3325 0.9813 0.6488 195.1561
31 || 0.9813 0.2248 -0.7565 -77.0952
32 || 0.2248 0.0736 -0.1511 -67.2344
33 || 0.0736 0.4579 0.3842 521.7083
34 || 0.4579 0.7498 0.2920 63.7669
35 || 0.7498 1.7277 0.9779 130.4160
36 || 0.7277 1.1158 0.3881 53.3394
37 || 0.1158 1.0781 0.9623 830.8925
38 || 0.0781 1.7854 1.7073 2185
39 || 0.7854 0.4648 -0.3206 -40.8249
__________________________________________________________
The COMPARE Procedure
Comparison of WORK.ONE with WORK.TWO
(Method=EXACT)
R=2
Value Comparison Results for Variables
__________________________________________________________
|| Base Compare
Obs || U U Diff. % Diff
________ || _________ _________ _________ _________
||
21 || 0.8614 0.8614 0 0
22 || 0.9198 0.9198 0 0
23 || 1.0402 1.0402 0 0
24 || 0.3902 0 -0.3902 -100.0000
25 || 1.1313 1.1313 0 0
26 || 1.2154 1.2154 0 0
27 || 0.9156 0.9156 0 0
28 || 1.5620 1.5620 0 0
29 || 1.3531 1.3531 0 0
30 || 1.2319 0 -1.2319 -100.0000
31 || 0.1938 1.3441 1.1503 593.6082
32 || 1.3441 1.4971 0.1530 11.3821
33 || 1.4971 1.0952 -0.4019 -26.8432
34 || 1.0952 0 -1.0952 -100.0000
35 || 0.7230 0 -0.7230 -100.0000
36 || 0.7559 1.4547 0.6989 92.4574
37 || 1.4547 1.4926 0.0379 2.6030
38 || 1.4926 0 -1.4926 -100.0000
39 || 0.6674 1.0874 0.4200 62.9251
__________________________________________________________
The COMPARE Procedure
Comparison of WORK.ONE with WORK.TWO
(Method=EXACT)
R=3
Observation Summary
Observation Base Compare
First Obs 41 20
First Unequal 41 20
Last Unequal 59 38
Last Match 59 38
Last Obs 60
Number of Observations in Common: 19.
Number of Observations in WORK.ONE but not in WORK.TWO: 1.
Total Number of Observations Read from WORK.ONE: 20.
Total Number of Observations Read from WORK.TWO: 19.
Number of Observations with Some Compared Variables Unequal: 13.
Number of Observations with All Compared Variables Equal: 6.
Values Comparison Summary
Number of Variables Compared with All Observations Equal: 0.
Number of Variables Compared with Some Observations Unequal: 3.
Total Number of Values which Compare Unequal: 34.
Maximum Difference: 9.
All Variables Compared have Unequal Values
Variable Type Len Ndif MaxDif
S NUM 8 11 9.000
T NUM 8 10 1.394
U NUM 8 13 1.277
Value Comparison Results for Variables
__________________________________________________________
|| Base Compare
Obs || S S Diff. % Diff
________ || _________ _________ _________ _________
||
41 || 1.0000 0 -1.0000 -100.0000
42 || 2.0000 2.0000 0 0
43 || 3.0000 3.0000 0 0
44 || 4.0000 4.0000 0 0
45 || 5.0000 5.0000 0 0
46 || 6.0000 6.0000 0 0
47 || 7.0000 7.0000 0 0
48 || 8.0000 8.0000 0 0
49 || 9.0000 9.0000 0 0
The COMPARE Procedure
Comparison of WORK.ONE with WORK.TWO
(Method=EXACT)
R=3
Value Comparison Results for Variables
__________________________________________________________
|| Base Compare
Obs || S S Diff. % Diff
________ || _________ _________ _________ _________
||
50 || 10.0000 11.0000 1.0000 10.0000
51 || 11.0000 12.0000 1.0000 9.0909
52 || 12.0000 13.0000 1.0000 8.3333
53 || 13.0000 14.0000 1.0000 7.6923
54 || 14.0000 15.0000 1.0000 7.1429
55 || 15.0000 16.0000 1.0000 6.6667
56 || 16.0000 17.0000 1.0000 6.2500
57 || 17.0000 18.0000 1.0000 5.8824
58 || 18.0000 19.0000 1.0000 5.5556
59 || 19.0000 10.0000 -9.0000 -47.3684
__________________________________________________________
__________________________________________________________
|| Base Compare
Obs || T T Diff. % Diff
________ || _________ _________ _________ _________
||
41 || 0.8818 0.8818 0 0
42 || 0.3351 0.3351 0 0
43 || 0.8039 0.8039 0 0
44 || 0.9810 0.9810 0 0
45 || 0.2145 0.2145 0 0
46 || 0.0999 0.0999 0 0
47 || 0.0676 0.0676 0 0
48 || 0.3473 0.3473 0 0
49 || 0.0413 0.0413 0 0
50 || 0.7923 0.2893 -0.5030 -63.4860
51 || 0.2893 0.8140 0.5247 181.3931
52 || 0.8140 0.8064 -0.007607 -0.9344
53 || 0.8064 0.7381 -0.0683 -8.4682
54 || 0.7381 0.3667 -0.3714 -50.3199
55 || 0.3667 1.5490 1.1823 322.4229
56 || 0.5490 1.7332 1.1841 215.6722
57 || 0.7332 1.5802 0.8470 115.5262
58 || 0.5802 1.9738 1.3936 240.1767
59 || 0.9738 0.2221 -0.7518 -77.1971
__________________________________________________________
The COMPARE Procedure
Comparison of WORK.ONE with WORK.TWO
(Method=EXACT)
R=3
Value Comparison Results for Variables
__________________________________________________________
|| Base Compare
Obs || U U Diff. % Diff
________ || _________ _________ _________ _________
||
41 || 0.4911 0 -0.4911 -100.0000
42 || 1.2291 1.2291 0 0
43 || 0.6371 0 -0.6371 -100.0000
44 || 0.1953 0 -0.1953 -100.0000
45 || 1.3546 1.3546 0 0
46 || 1.4707 1.4707 0 0
47 || 1.5032 1.5032 0 0
48 || 1.2161 1.2161 0 0
49 || 1.5295 1.5295 0 0
50 || 0.6563 1.2773 0.6210 94.6256
51 || 1.2773 0 -1.2773 -100.0000
52 || 0.6197 0 -0.6197 -100.0000
53 || 0.6327 0.7405 0.1078 17.0343
54 || 0.7405 1.1953 0.4548 61.4228
55 || 1.1953 0 -1.1953 -100.0000
56 || 0.9896 0 -0.9896 -100.0000
57 || 0.7478 0 -0.7478 -100.0000
58 || 0.9518 0 -0.9518 -100.0000
59 || 0.2294 1.3469 1.1175 487.1725
__________________________________________________________
The COMPARE Procedure
Comparison of WORK.ONE with WORK.TWO
(Method=EXACT)
R=4
Observation Summary
Observation Base Compare
First Obs 61 39
First Unequal 61 39
Last Unequal 79 57
Last Match 79 57
Last Obs 80
Number of Observations in Common: 19.
Number of Observations in WORK.ONE but not in WORK.TWO: 1.
Total Number of Observations Read from WORK.ONE: 20.
Total Number of Observations Read from WORK.TWO: 19.
Number of Observations with Some Compared Variables Unequal: 12.
Number of Observations with All Compared Variables Equal: 7.
Values Comparison Summary
Number of Variables Compared with All Observations Equal: 0.
Number of Variables Compared with Some Observations Unequal: 3.
Total Number of Values which Compare Unequal: 32.
Maximum Difference: 9.
All Variables Compared have Unequal Values
Variable Type Len Ndif MaxDif
S NUM 8 11 9.000
T NUM 8 10 1.277
U NUM 8 11 1.328
Value Comparison Results for Variables
__________________________________________________________
|| Base Compare
Obs || S S Diff. % Diff
________ || _________ _________ _________ _________
||
61 || 1.0000 0 -1.0000 -100.0000
62 || 2.0000 2.0000 0 0
63 || 3.0000 3.0000 0 0
64 || 4.0000 4.0000 0 0
65 || 5.0000 5.0000 0 0
66 || 6.0000 6.0000 0 0
67 || 7.0000 7.0000 0 0
68 || 8.0000 8.0000 0 0
69 || 9.0000 9.0000 0 0
The COMPARE Procedure
Comparison of WORK.ONE with WORK.TWO
(Method=EXACT)
R=4
Value Comparison Results for Variables
__________________________________________________________
|| Base Compare
Obs || S S Diff. % Diff
________ || _________ _________ _________ _________
||
70 || 10.0000 11.0000 1.0000 10.0000
71 || 11.0000 12.0000 1.0000 9.0909
72 || 12.0000 13.0000 1.0000 8.3333
73 || 13.0000 14.0000 1.0000 7.6923
74 || 14.0000 15.0000 1.0000 7.1429
75 || 15.0000 16.0000 1.0000 6.6667
76 || 16.0000 17.0000 1.0000 6.2500
77 || 17.0000 18.0000 1.0000 5.8824
78 || 18.0000 19.0000 1.0000 5.5556
79 || 19.0000 10.0000 -9.0000 -47.3684
__________________________________________________________
__________________________________________________________
|| Base Compare
Obs || T T Diff. % Diff
________ || _________ _________ _________ _________
||
61 || 0.4050 0.4050 0 0
62 || 0.6630 0.6630 0 0
63 || 0.5887 0.5887 0 0
64 || 0.6848 0.6848 0 0
65 || 0.1850 0.1850 0 0
66 || 0.7362 0.7362 0 0
67 || 0.1418 0.1418 0 0
68 || 0.8857 0.8857 0 0
69 || 0.7377 0.7377 0 0
70 || 0.5416 0.3993 -0.1423 -26.2704
71 || 0.3993 0.3226 -0.0767 -19.2033
72 || 0.3226 0.2407 -0.0819 -25.3852
73 || 0.2407 0.7858 0.5451 226.4241
74 || 0.7858 0.6084 -0.1774 -22.5735
75 || 0.6084 1.2410 0.6326 103.9680
76 || 0.2410 1.4124 1.1714 486.0181
77 || 0.4124 1.6893 1.2769 309.6072
78 || 0.6893 1.1069 0.4176 60.5897
79 || 0.1069 0.0474 -0.0595 -55.6166
__________________________________________________________
The COMPARE Procedure
Comparison of WORK.ONE with WORK.TWO
(Method=EXACT)
R=4
Value Comparison Results for Variables
__________________________________________________________
|| Base Compare
Obs || U U Diff. % Diff
________ || _________ _________ _________ _________
||
61 || 1.1539 1.1539 0 0
62 || 0.8460 0.8460 0 0
63 || 0.9414 0.9414 0 0
64 || 0.8165 0.8165 0 0
65 || 1.3847 1.3847 0 0
66 || 0.7434 0.7434 0 0
67 || 1.4285 1.4285 0 0
68 || 0.4827 0 -0.4827 -100.0000
69 || 0.7411 0.7411 0 0
70 || 0.9984 1.1600 0.1616 16.1819
71 || 1.1600 1.2423 0.0823 7.0914
72 || 1.2423 1.3277 0.0854 6.8739
73 || 1.3277 0 -1.3277 -100.0000
74 || 0.6668 0.9167 0.2499 37.4856
75 || 0.9167 1.3274 0.4107 44.7991
76 || 1.3274 0 -1.3274 -100.0000
77 || 1.1457 0 -1.1457 -100.0000
78 || 0.8103 1.4637 0.6534 80.6332
79 || 1.4637 1.5233 0.0596 4.0748
__________________________________________________________
DATA SET OUT
R S _TYPE_ _OBS_ T U
2 -1 DIF 1 E E
2 E DIF 4 E -0.39020
2 1 DIF 10 0.64882 -1.23188
2 1 DIF 11 -0.75652 1.15032
2 1 DIF 12 -0.15112 0.15299
2 1 DIF 13 0.38421 -0.40187
2 1 DIF 14 0.29196 -1.09522
2 1 DIF 15 0.97787 -0.72302
2 1 DIF 16 0.38814 0.69885
2 1 DIF 17 0.96231 0.03787
2 1 DIF 18 1.70728 -1.49258
2 -9 DIF 19 -0.32064 0.41999
3 -1 DIF 1 E -0.49107
3 E DIF 3 E -0.63705
3 E DIF 4 E -0.19531
3 1 DIF 10 -0.50297 0.62102
3 1 DIF 11 0.52474 -1.27732
3 1 DIF 12 -0.00761 -0.61974
3 1 DIF 13 -0.06829 0.10778
3 1 DIF 14 -0.37143 0.45483
3 1 DIF 15 1.18234 -1.19533
3 1 DIF 16 1.18415 -0.98957
3 1 DIF 17 0.84703 -0.74779
3 1 DIF 18 1.39358 -0.95179
3 -9 DIF 19 -0.75175 1.11749
4 -1 DIF 1 E E
4 E DIF 8 E -0.48272
4 1 DIF 10 -0.14228 0.16157
4 1 DIF 11 -0.07668 0.08226
4 1 DIF 12 -0.08190 0.08539
4 1 DIF 13 0.54509 -1.32767
4 1 DIF 14 -0.17739 0.24994
4 1 DIF 15 0.63258 0.41068
4 1 DIF 16 1.17139 -1.32738
4 1 DIF 17 1.27686 -1.14570
4 1 DIF 18 0.41763 0.65338
4 -9 DIF 19 -0.05946 0.05964
This example demonstrates how to compare two data sets using PROC COMPARE.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> COMPARE
|
| Date Modified: | 2005-11-08 03:03:19 |
| Date Created: | 2005-05-23 13:47:24 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |