There's several ways to open SPSS data files. The right way, however, is by syntax. The way we typically do so in practice may differ somewhat from what you're used to. But give it a shot. It keeps things nicely organized and this eventually saves time and effort. We'll use employees.sav throughout.
Creating a Project Folder
A previous tutorial recommended keeping your project files (that is, data, syntax, output and other files) together in a single folder. We first create this new folder and in it we'll create another folder which we call something like “original_data” or perhaps just “ori”. The screenshot below shows the result.
Copy Data File into Ori Folder
We'll now copy the original data file into the “ori” folder. Why? Well, it should be in our project folder rather than in an email or on a client's web server or something. This is because we want to make very sure the original data file -as we received it- gets backed up with the rest of our work. Second, putting it in a subfolder keeps it safely apart from the files we'll create and edit during the project.
Set SPSS Default Folder to Project Folder
Right, now we'll run SPSS and open a new syntax file. Next, we'll copy-paste the path to our project folder from its window into our syntax file. The result is shown below.
Next, we'll type a CD command around the path we just pasted. In our case, this results in cd 'D:\employees'. We run this line in order to set our project folder as SPSS’ default directory. If you're not sure whether that actually worked, running show dir. will tell you what's been set as SPSS’ default directory.
Open Data File
Right, now we'll move into the “ori” folder and copy the name of our data file. It can be selected by pressing f2 after left clicking it.
We paste the filename to the end of our syntax and prefix it with ori/
. Next, we'll type a GET FILE
command around it, resulting in
get file 'ori/employees.sav'.
Running this command will open the original data file from the “ori” subfolder.
Saving SPSS Data with Syntax
In practice, this is where you'll probably start inspecting, editing and analyzing your data. We'll skip that part, since it's not the focus of this tutorial. However, setting SPSS’ default directory makes it very easy to save your (edited) data to your project folder. You can do so by simply running something like save outfile '10_edited_data.sav'. Finally, save your syntax file into your project folder and you've all your project files nicely organized like we proposed in SPSS - Combining Data with Syntax and Output.
End Result
By following the steps described in this tutorial, your final syntax file will look somewhat like the syntax below.
cd 'D:\employees'.
*2. Open data.
get file 'ori\employees.sav'.
*3. (Other commands).
*4. Save data.
save outfile '10_edited_data.sav'.
Final Notes
The main point of this tutorial is that by using CD
, we need to include our project folder just once in our syntax. If we decide to move the entire folder or change its name, all we need to change is a single CD command at the top of our syntax file. This pays off by avoiding accidents and keeping things organized.
THIS TUTORIAL HAS 15 COMMENTS:
By Qudus on June 9th, 2016
I have been able to rectify the problem. I did not include quote (') while pasting the path. Thanks and sorry for disturbing you unnecessarily. God bless you
By Ruben Geert van den Berg on June 10th, 2016
No problem! God bless you too man!
By Jack Hoffman on October 17th, 2018
I've worked a lot with sql, so I'm comfortable writing queries. I like these syntax commands, and I like being able to write a batch command to open all files for a particular project. However, I can't open the output file--*.spv--with the 'get file' command. I keep getting a 5263 error: "input data file is neither an SPSS Statistics data file nor an
>SPSS/PC+ data file." Any suggestions?
By Ruben Geert van den Berg on October 17th, 2018
Hi Jack!
Use GET FILE only for SPSS data files with the .sav extension.
An SPSS file with the .spv extension is an SPSS output file. You can open it with OUTPUT OPEN FILE = '...'.
Note that SPSS output files used to have the .spo extension until SPSS version 16 or so. Old SPSS versions can't open .spv files but newer SPSS versions can open .spo files.
Hope that helps!
SPSS tutorials
By Jack Hoffman on October 17th, 2018
Ruben,
Thanks so much. This was a big help.
Jack