4. Part II: Using Syntax

4.3. Using syntax to ... save data

Obviously when you create or are given a data set for your work, you need to save this file somewhere sensible.  It’s really bad practice to use it from your ‘downloads’ folder, or your desktop (just for example … and yes, people actually do this … but not you!).

 

The key command for saving an SPSS data file:

 

Once you’ve decided where you’re going to save your files (you would have already done this when defining your working directory, so we should be ok at this point), you can use the save command to save your file where you want it.

For those of you who are still not entirely comfortable with the concept of using/writing syntax yet, let’s first use the menus and then paste the save syntax into our open syntax file.

  1. Click File > Save as …
  2. Navigate to the working directory (where you want to save your file)
  3. Click Paste (right hand side of dialogue box)
  4. Click Yes to replacing the existing file (if that message appears…)

 

Your open syntax file should now have a save command, which you should comment something like this:

save file 2

 

The thing is, though, that we’ve set the working directory already, so there’s a bit of inefficiency going on here.  Also, the syntax is pretty straightforward, so let’s have a go at writing it ourselves, making use of the fact that we’ve also set the working directory up front.

 

  Task: Save your SPSS dataset

1. Type the following into your syntax file:

save outfile="HLTH1025_2016.sav" /compressed.

The outfile criteria tells SPSS that we want to “save out” the file to a location, which equals (=) the location we specify in quotation marks.  Since we set the working directory, we now don’t need to specify the whole file path – just the file name.  SPSS now knows that we want everything saved to the working directory.  Efficiency!

The text at the end of the command – /compressed – tells SPSS to compress the data file to save space.  This is an “option” for the save command (most commands have one or more options to be more specific about what you want SPSS to do) – options are highlighted in green.

2. Save your syntax file (CTRL + S will do the trick!).