A common problem is transferring data from one statistical package to another. Converting data from SPSS to SAS is not very difficult, as the example below illustrates. We start by first building an SPSS file below that we will use for our examples.
DATA LIST LIST / make (A17) price mpg rep78 modtype . BEGIN DATA. "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 END DATA.
If you had your data in an SPSS .sav file (say c:auto.sav) you would instead read it as shown below.
GET FILE = "c:auto.sav".
In order to convert your file to SAS, you first need to create an SPSS portable file, as shown below. SAS can read SPSS portable files (but it cannot read SPSS .sav files).
EXPORT OUTFILE = "c:auto.por". DISPLAY DICTIONARY. DESCRPTIVES /VAR=ALL.
The display dictionary and descriptives /var=all commands are used to get information about the current file so we can verify that our conversion was error free. The output of these commands is shown below.
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
Now that we can read auto.por into SAS using the SAS program shown below. We use proc contents and proc means to inspect the file to verify that the file was converted properly.
LIBNAME in SPSS 'c:auto.por'; DATA cars; SET in.auto; RUN;
PROC CONTENTS DATA = cars; RUN; PROC MEANS DATA = cars; RUN;
You can compare the output below for the SAS file with the output above from the SPSS file and see that the file was converted successfully.
CONTENTS PROCEDURE Data Set Name: WORK.CARS Observations: 16 Member Type: DATA Variables: 5 Engine: V612 Indexes: 0 Created: 12:25 Sunday, Oct 10, 1999 Observation Length: 52 Last Modified: 12:25 Sunday, Oct 10, 1999 Deleted Observations: 0 Protection: Compressed: NO Data Set Type: Sorted: NO Label: [portion omitted to save space]
-----Alphabetic List of Variables and Attributes----- # Variable Type Len Pos Format --------------------------------------------- 1 MAKE Char 20 0 20. 5 MODTYPE Num 8 44 8.2 3 MPG Num 8 28 8.2 2 PRICE Num 8 20 8.2 4 REP78 Num 8 36 8.2 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 ----------------------------------------------------
Should you want to save the file as a permanent data set, modify the program to include a libname statement defining the output destination of the SAS file.
LIBNAME in SPSS 'c:auto.por'; LIBNAME out 'c:'; DATA out.cars; SET in.auto; RUN;
Please note. If you move SPSS portable files (.por files) using ftp they must be transported as ascii. For more information on using FTP, see Transferring Files with FTP.