Generating and grabbing SPSS syntax which is automatically generated

SPSS syntax

Grabbing SPSS Syntax

I’ve asked a few of my colleagues and we estimate that around 90% of SPSS users only use the GUI interface.  While the GUI interface has it’s merits (I still use it from time to time) using syntax is one of the best ways to be more productive.

In the below video I demonstrate three ways to get /create SPSS syntax generated by using the GUI interface.  This is a great way to begin learning how to utilize code!

Generating and grabbing SPSS syntax which is automatically generated

 

 

Why you should learn SPSS syntax- Intro tutorial & demo video

SPSS syntax

Why you should learn SPSS syntax

For more than a decade I’ve been teaching people SPSS syntax, macros, and scripts.   Somehow throughout that time I never wrote this post to help explain some of the main benefits of using syntax over the GUI interface.  To me there are lots of reasons why you should make it a priority to learn how to code in SPSS.  I’ve made an attempt to prioritize them and demonstrated many in the below video.

  1. Without any real additional work you can reuse:
    • renaming of variables
    • setting variable labels
    • define format (numeric, scale, dates, % etc)
    • regroup variables
  2. Work ahead-
    • Export small amount of data on initial kick-off and work on the data file/format.
    • Have the frame-work of your report done.
    • Then, when done collecting data, export and write-up analysis
  3. @from Jon Peck- Review what analysis was run in the past.  Determine what you (or perhaps a colleague scratching his head) did  right/wrong or just borrow from the past.  (Hint* did you know there is a log file you can check which might have all GUI/syntax you have ever run?  I mention it in this video.)
  4. Redo analysis done on different data set
  5. Create macros (special type of SPSS syntax) to re-purpose code for an amazing time savings!
  6. Apply similar re-coding / analytics on multiple variables
  7. Macros– True gems of saving time
  8. Some things are only available in syntax
  9. Allow for re-applying settings
  10. Use from other sources (labels from questionnaire ,database, etc.)

In the video below I explain the above concepts and I firmly believe that, after watching the video, you’ll understand why learning SPSS syntax is a great next step for you.

Why you should learn to use SPSS synatx

 

Using First & Last variables for SPSS Syntax- Great way to reduce your code

SPSS syntax

In SPSS syntax you can streamline your code by putting the word “TO” between the first and last variable you want.  For instance, in the image below, Category, Lang, cname, Date, and Sent is highlighted. If I wanted to run frequencies perform something on all of these variables I could write the following code:

or I could simply do the following:

Both return the same results yet the second one is much simpler, cleaner and can save a lot of space (especially when there are dozens of variables).

I have a short AutoHotKey script which grabs the variables highlighted, copies them to the clipboard and takes the first item, then puts the word ” TO ” then grabs the list item.

This helps me write clean-looking syntax much faster than doing it manually.

Grabbing first and last variable with SPSS syntax

Grabbing First and Last variables for SPSS Syntax

 

The following is the AutoHotKey code:

 


SPSS Syntax writer / Recoder using an Excel template

SPSS syntax

SPSS syntax

Writing (and re-writing) SPSS syntax can be mundane and time consuming.  Sometimes my data set has hundreds of variables which would take me quite some time to rename and relabel.  I created an Excel template which generates the necessary syntax and greatly helped automate the process.

The Excel file is available for download from here and the video below helps you see how easy it can be to use.  There is also a concatenation tab which allows you to add specific words as a prefix for your variables.

SPSS Syntax Writer