Q: I need to get data from SPSS into SAS (or Stata to SAS, Excel to SAS, ...)

A: This became easy when SAS introduced the import procedure. Suppose your SPSS data file is yourdata.sav. There are two steps in converting to SAS:

  1. In SPSS, save your file as a tab-delimited text file. From the File menu, choose Save as…, then choose Tab-delimited (*.dat) from the Save as type pull-down menu, and check the box that reads "Write variable names to spreadsheet." In the File name field, choose a location and name (e.g., yourdata) for your tab-delimited data file, but don’t include the .dat extension. SPSS will append this extension automatically.
  2. In SAS, convert the tab-delimited file to a permanent SAS data set. You do this with the following code, making appropriate substitutions for the italicized text. Note that, when you specify the input file in SAS, you do need to include the .dat extension:
libname output_library 'output_drive:\output_directory\';
proc import
 datafile='input_drive:\input_directory\yourdata.dat'
 dbms=TAB out=output_library.yourdata replace;
run;
If you look in output_drive:\output_directory, you should now have a file named yourdata.sas7bdat (assuming you are running SAS 7). This file is a permanent SAS data set that you can reference in any program that uses your output_library library reference.

Permanent SAS data sets and the import procedure are covered in Delwiche & Slaughter, The Little SAS Book: A Primer, as well as the SAS documentation.

The basic approach is the same if you want to get a file from Stata to SAS or Excel to SAS. Just generate a text file and import it. Actually most software will export and import text files, so this is a fairly general method for getting data between programs.

Technical quirk: SAS uses the first 8-10 lines to identify the variable types and lengths. If those lines are not typical -- for example, if the first 8-10 values are missing or shorter than' average, SAS may mistype or truncate some of the variables. Before exporting, you should sort the SPSS data to make sure this doesn't happen. If this is impractical, don't use the SAS import procedure. Instead, use the StatTransfer program available in the SRL.