
Proc Compare – Stat 480
James D. Abbey
January 19, 2006
1. Enter your SAS data sets for comparison. Ideally, the data sets will match
entirely. In this exercise, data1 will be correct while data2 will have flaws.
a. SAS Code for Data Entry:
i. Data data1; specifies that you are entering data into SAS and
names the data “data1”
ii. infile ‘C:\Temp\data1.txt’; points to an external file on your hard-
drive. You could also have used a “datalines;” command to enter
the data directly into SAS.
iii. Input var1 1 var2 2…; specifies what variables to input. The
number following the variable name is a column flag, which tells
SAS to look for data in column 1, 2, etc.
1. Other input options are a space, tab, comma, etc.
a. Space and tab will be treated the same in SAS and
require no special syntax. Use of a comma will be
covered later.
iv. Run; tells SAS to execute the commands above.
b. A view of our sample data:
i. Data1: Data2:
ii. As you can see, the errors occur in the following observations
(lines):
1. Observation 2 swaps the second and third columns
2. Observation 3 swaps the first and second columns
3. Observation 5 swaps the third and fourth columns
4. Observation 7 is missing the first piece of data
2. Using PROC COMPARE
a. SAS syntax:
i. We use the proc compare to compare data sets in many ways. In
our example, we will go element-wise.
ii. base = data 1 compare = data2 informs SAS that we are
comparing data1 to data2