Accessing SPSS Files

Overview of SPSS Files

The SPSS engine supports native and portable file formats for both SPSS and SPSS-X files. The engine automatically determines which type of SPSS file it is reading and reads the file accordingly. The SPSS engine supports character variable lengths up to 32K.
Note: The SPSS engine supports SPSS save files for SPSS Release 9 and earlier releases. It also supports SPSS-X and the SPSS portable file format that is created by using the SPSS EXPORT command. If you create a system file in a later version of SPSS, you need to use SPSS to resave the data in the export format.
This engine can read only SPSS data files that were created under the same operating environment. For example, the SPSS engine under z/OS cannot read SPSS files that were created under the UNIX operating environment. The only exception is an SPSS portable file, which can originate from any operating environment.

Assigning a Libref to an SPSS File

In order to access an SPSS file, you must use the LIBNAME statement or LIBNAME function to assign a libref to the file. Specify the SPSS engine in the LIBNAME statement as follows:
LIBNAME libref SPSS 'physical-filename ';
libref
is a SAS libref.
SPSS
is the SPSS engine.
physical-filename
is the physical filename of the SPSS file.
The syntax of the LIBNAME function for SPSS is as follows:
LIBNAME(libref, 'physical-filename', 'SPSS')
You do not need to use a LIBNAME statement or function before running PROC CONVERT if you are using PROC CONVERT to convert an SPSS file to a SAS data file. For more information, see CONVERT Procedure: z/OS.
Note that the LIBNAME statement and function have no options for the SPSS engine.
If you previously used a TSO ALLOC command or a JCL DD statement to assign a ddname to the SPSS file, then you can omit the physical-filename in the LIBNAME statement or function and use the ddname as the libref. For more information, see the second example in Examples of Accessing SPSS Files.

Referencing SPSS Files

SPSS data files do not have names. For these files, use a member name of your choice in SAS programs.
SPSS data files have only one logical member per file. Therefore, you can use _FIRST_ in your SAS programs to refer to the first data file.

Reformatting SPSS Files

SAS cannot use SPSS files that contain variables with numeric formats that have a larger number of decimal places than the width of the entire variable. For example, if you have a variable that has a width of 17 and also has 35 decimal places, then SAS will return errors when you try to run a DATA step on the file or view it with the table viewer. To use the SPSS file with SAS, you have to reformat the variables.
You can reformat the variables by reducing the number of decimal spaces to a value that will fit within the width of the variable. In the following code example the statement revision=cat(format,formatl,'.2'); converts the number of decimal spaces to 2. This value reduces the number of decimal spaces so that it is not greater than the width of the variable.
libname abc spss 'FILENAME.POR';
proc contents data=abc._all_ out=new; run;
filename sascode temp;
data _null_; set new; file sascode;
     if formatd > formatl then do;
        revision=cat(format,formatl,'.2');
        put 'format' +1 name +1 revision ';' ;
        end;
     run;
data temp; set abc._all_;
     %inc sascode/source2;
     run;
Note: The OPTIONS NOFMTERR statement does not allow SAS to use the data set with a DATA step or the table viewer. You have to reformat numeric variables that have a larger decimal value than their width before you can use a DATA step or the table viewer.

Examples of Accessing SPSS Files

Suppose you want to read the physical file MY.SPSSX.FILE. The following statements assign a libref to the data set and then run PROC CONTENTS and PROC PRINT on the SPSS file:
libname xxx spss 'my.spssx.file';
proc contents data=xxx._first_;
proc print data=xxx._first_;
run;
In the next example, the TSO ALLOC command associates a ddname with the name of the physical file that comprises the SPSS physical-filename. The physical filename is omitted in the LIBNAME statement, because the libref that is used is the same as the ddname in the TSO command. The PROC PRINT statement prints the data in the first member of the SPSS data file.
tso alloc f(xxx) da('my.spssx.file') shr reu;
libname xxx spss;
proc print data=xxx._first_;
run;