SAS How To's

How to Export a SAS dataset as an SPSS .sav file

Many researchers and data analysts use multiple tools to carry out their work. For example, SAS for data manipulation and SPSS for data analysis. In this case, it’s important to know how to move your data from one tool to another. Therefore, we discuss in this article how to export a SAS dataset as an SPSS .sav file.

You can convert a SAS dataset into an SPSS .sav file with the PROC EXPORT procedure. This procedure lets you define which SAS dataset you want to export, as well as the output location of the .sav file. By adding additional code, the PROC EXPORT procedure overwrites existing .sav files or exports header labels instead of header names.

In the remainder of this post, we discuss the correct syntax of the PROC EXPORT procedure and show examples of how to save SAS datasets as an SPSS file.

Do you know? How to Export a SAS Dataset as CSV, TXT, or Excel file

How to Export a SAS Dataset to SPSS?

Saving a SAS dataset as a .sav file is easy. You only need to call the PROC EXPORT procedure and provide 3 mandatory arguments.

These are the steps to export a SAS dataset as an SPSS .sav file

  1. Start the EXPORT procedure

    You start the EXPORT procedure with the PROC EXPORT statement.

  2. Define the SAS dataset

    You use the DATA=-option to define the SAS dataset you want to export, i.e., the dataset you want to convert in a .sav file.

  3. Define the output location

    You define the output local (i.e., the location of the .sav file) with the FILE=-option. You must provide the full path, the name of the file, and the .sav extension. All written between (double) quotes.

  4. Specify the file format

    You specify the format of the output file with the DBMS=-option. To save a SAS dataset as a .sav file you use DBMS=sav.

  5. Run the EXPORT procedure

    Finally, to export your SAS dataset you finish your code with the RUN statement.

In the example below, we will convert the CARS dataset from the SASHELP library into an SPSS file.

We use the following SAS code.

proc export data=sashelp.cars
    file="/home/data/cars.sav"
    dbms=sav;
run;

The SAS log tells us that the .sav file was created successfully.

How to Overwrite Existing .SAV Files in SAS?

If you would re-run the code above, SAS would write a note to the log and stop the export. SAS aborts the export because, by default, it doesn’t overwrite existing files.

For example:

However, oftentimes, you want to update the data in a file without changing the name. So, how do you overwrite an existing .sav-file in SAS?

In SAS, you can export a SAS dataset and overwrite an existing SPSS file with the REPLACE option. This option is part of the PROC EXPORT procedure and must be placed after the DBMS=-option.

The following example shows how to use the REPLACE statement.

proc export data=sashelp.cars
    file="/home/data/cars.sav"
    dbms=sav
    replace;
run;

How to Export a SAS Dataset to SPSS with Column Labels?

By default, PROC EXPORT exports a SAS dataset with the column names (i.e., variable names). However, if your dataset has variable labels you might want to export those instead.

You can export a SAS dataset to a .sav-file with the variable labels instead of the variable names with the LABELS statement. This statement is part of the PROC EXPORT procedure and must be placed before the REPLACE option.

The SAS code below shows how to use the LABELS statement.

proc export data=sashelp.cars
    file="/home/data/cars_variable_labels.sav"
    dbms=sav
    label
    replace;
run;