A common problem is transferring data from one statistical package to another. If you are converting a SAS to SPSS using SPSS version 11 and above, then see this FAQ for a simpler procedure.
Otherwise, this example is more general and will work for any version of SAS and any version of SPSS. We first build a SAS file named auto that we will use to for our examples.
DATA auto ; LENGTH make $ 20 ; INPUT make $ 1-17 price mpg rep78 modtype ; CARDS; AMC Concord 4099 22 3 2 AMC Pacer 4749 17 3 2 Audi 5000 9690 17 5 3 Audi Fox 6295 23 3 1 BMW 320i 9735 25 4 1 Buick Century 4816 20 3 2 Buick Electra 7827 15 4 2 Buick LeSabre 5788 18 3 2 Cad. Eldorado 14500 14 2 3 Olds Starfire 4195 24 1 2 Olds Toronado 10371 16 3 2 Plym. Volare 4060 18 2 2 Pont. Catalina 5798 18 4 2 Pont. Firebird 4934 18 1 1 Pont. Grand Prix 5222 19 3 2 Pont. Le Mans 4723 19 3 1 ; RUN;
Every SAS data set is accessed through an engine, which is basically a set of instructions that tells SAS how to read and write data of a particular type. SAS supports a variety of interface engines, which enable it to read and write files in foreign file formats. The SAS xport engine is a set of instructions that reads and writes portable SAS files. Portable SAS files are written in platform independent format, which means they can be moved to another computer and read by SAS on any operating system. SAS export files can also be read directly into SPSS.
The following program creates an xport file from the auto file and writes it out as a file named auto.xpt. The xpt extension is not required, but it is a convention that makes it easier to remember that the file is an export file. Please note that the export engine supports data step functionality, so you can subset records from the file, create new variables, etc. We also perform a proc contents and proc means in order to examine the xport file and to compare to the SPSS version to verify that the conversion was error free.
LIBNAME outdata XPORT 'c:auto.xpt' ; DATA outdata.auto ; SET auto; RUN; PROC CONTENTS DATA=outdata.auto ; RUN; PROC MEANS DATA=outdata.auto; RUN;
The output is shown below. Note that the proc contents reports a period for the number of observations. This is not a mistake or error. The proc contents is unable to count the number of observations in the file so it reports that as missing.
CONTENTS PROCEDURE Data Set Name: OUTDATA.AUTO Observations: . Member Type: DATA Variables: 5 Engine: XPORT Indexes: 0 Created: 11:24 Sunday, Oct 10, 1999 Observation Length: 52 Last Modified: 11:24 Sunday, Oct 10, 1999 Deleted Observations: 0 Protection: Compressed: NO Data Set Type: Sorted: NO Label: -----Alphabetic List of Variables and Attributes----- # Variable Type Len Pos ----------------------------------- 1 MAKE Char 20 0 5 MODTYPE Num 8 44 3 MPG Num 8 28 2 PRICE Num 8 20 4 REP78 Num 8 36 Variable N Mean Std Dev Minimum Maximum ---------------------------------------------------------- PRICE 16 6675.13 2967.77 4060.00 14500.00 MPG 16 18.94 3.15 14.00 25.00 REP78 16 2.94 1.06 1.00 5.00 MODTYPE 16 1.88 0.62 1.00 3.00 ----------------------------------------------------------
We should inspect the log to make sure there are no errors, and also while inspecting the log we can confirm how many observations were written to the file. As we see below, the file has 16 observations.
NOTE: The data set OUTDATA.AUTO has 16 observations and 5 variables. NOTE: DATA statement used: real time 0.10 seconds cpu time 0.03 seconds
We now have a SAS xport file called c:auto.xpt that we can read directly into SPSS using the get sas command as illustrated in the SPSS program below. We use display dictionary and descriptives /var=all to check the file to very that the file was converted without error.
GET SAS DATA='c:auto.xpt'. DISPLAY DICTIONARY. DESCRIPTIVES /VAR=ALL.
We can compare the output of the SPSS program below with the output of the SPSS program above and verify that the file was converted correctly.
File: File from SAS TRANSPORT DATA SET List of variables on the working file Name Position MAKE 1 Print Format: A20 Write Format: A20 PRICE 4 Print Format: F8.2 Write Format: F8.2 MPG 5 Print Format: F8.2 Write Format: F8.2 REP78 6 Print Format: F8.2 Write Format: F8.2 MODTYPE 7 Print Format: F8.2 Write Format: F8.2 Number of valid observations (listwise) = 16.00 Valid Variable Mean Std Dev Minimum Maximum N Label MAKE This is a string (alphanumeric) variable. PRICE 6675.13 2967.77 4060.00 14500.00 16 MPG 18.94 3.15 14.00 25.00 16 REP78 2.94 1.06 1.00 5.00 16 MODTYPE 1.88 .62 1.00 3.00 16