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 8th, 2016
Anytime I copy the path to the syntax file and run it, it brings an error message:
Warnings: Text: \ Command: CD
Invalid directory specification: :
Execution of this command stops.
By Ruben Geert van den Berg on June 8th, 2016
Hi Qudus!
It means that the folder you're trying to set does not exist on your computer. Are you working on a Mac by any chance? I'm not sure but I believe the backslash (\) doesn't occur in folders for Mac. Otherwise, you can try the Windows key + E. It'll open Windows explorer. You can paste your path into the address bar and see whether that actually opens the desired folder.
Hope that helps!
By Qudus on June 8th, 2016
I don't use a Mac. I have tried confirming the path and it's correct. I think what its talking about is that \ is an invalid text.
By Ruben Geert van den Berg on June 8th, 2016
Hi Qudus!
Something like
cd 'd:\temp'.
should run just fine. I used it a million times. If the problem persists, could you please post the entire CD command that's causing you trouble?By Qudus on June 9th, 2016
Thanks for your quick responses, the CD command is C:\Users\Adebayo Q\Desktop\employees