Select Variables and Save as a New File in SPSS

This tutorial shows how you can select variables and save them as a new file in SPSS (i.e., subset data file).

The easiest way is to use SPSS syntax to indicate which variables you want to select and where you want to save them as a new file. The following shows the key SPSS syntax.

Method 1: use comma to select variables:

/KEEP = Var1, Var2, Var3

Method 2: use TO to select variables:

/KEEP = Var1 TO Var3

Example for Method 1

We use the dataset from 2018 GSS. After downloading the data, you find that the GSS data file is very big (see the screenshot below) and you might want to select relevant variables and save them as a new file.

Select Variables and Save as a New File in SPSS using Syntax - Method 1- 1
Select Variables and Save as a New File in SPSS using Syntax – Method 1- 1

We can use the following SPSS syntax to select 3 variables of “DWELLPRE”, “EDUC”, and “EMAILHR” and save these variables as a new data file.

Note that, you can change information in ‘C:\new_datasets\dataset_new.sav’ to change where you want to save the file and the file name as well.

* select 3 variables (3 columns of data) in SPSS.
SAVE OUTFILE='C:\new_datasets\dataset_new.sav'
/KEEP = DWELLPRE, EDUC, EMAILHR
/COMPRESSED.

If you open the saved sav data file, you will see that there are only the 3 variables you selected (see the screenshot below).

Select Variables and Save as a New File in SPSS using Syntax -Method 1- 2
Select Variables and Save as a New File in SPSS using Syntax -Method 1- 2

Example for Method 2

You can also select a range of variables. For instance, you can select variables from “DWELLPRE” to “EMAILHR” (see the screenshot below).

Select Variables and Save as a New File in SPSS using syntax - Method 2 - 1
Select Variables and Save as a New File in SPSS using Syntax – Method 2 – 1

The following is the SPSS syntax to select a range of variables and save it as a new file.

* select a range of variables in SPSS.
SAVE OUTFILE='C:\new_datasets\dataset_new2.sav'
/KEEP = DWELLPRE TO EMAILHR 
/COMPRESSED.

If you open the file “dataset_new2.sav”, you will see the following. It includes variables from DWELLPRE to EMAILHR (see the screenshot below).

Select Variables and Save as a New File in SPSS using Syntax - Method 2 - 2
Select Variables and Save as a New File in SPSS using Syntax – Method 2 – 2

Further Reading