Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Tech Tips: Tips for working with syntax in IBM SPSS Statistics


Published on

Learn how to save, automate and repeat your analysis and more with the powerful syntax command language.

Published in: Data & Analytics
  • Be the first to comment

Tech Tips: Tips for working with syntax in IBM SPSS Statistics

  1. 1. Tips for working with syntax in IBM SPSS Statistics
  2. 2. • Use the paste button on any dialog box • Record commands in the log Edit –> Options –> Viewer • Retrieve commands from the journal file - statistics.jnl. Edit –> Options –> File Locations • Auto-complete in the syntax editor and build commands interactively How to create a syntax file 2
  3. 3. • Highlight the commands you want to run in a command syntax window • Invoke one command file from another using the INCLUDE or INSERT command • Use the production facility to run syntax files • Use the Statistics Batch Facility (Statistics Server) Running commands in a syntax file 3 •Utilities -> Production Facility
  4. 4.  It is often necessary to recode or modify original variables  Best practise is to assign the modified values to new variables and keep the original variables unchanged  Creating a new variable allows you to compare the initial and the modified values to verify the recode/modification has been done correctly Do not Overwrite Original Variables 4
  5. 5.  Instead of overwriting the variable always create a new one • COMPUTE var1=var1*2 • COMPUTE var1_new=var1*2 • RECODE var2 (1 thru5=1)(6 thru 10 = 2) • RECODE var2 (1 thru5=1)(6 thru 10 = 2)(ELSE=COPY) /INTO var2_new Overwriting Variables in Syntax 5
  6. 6.  For transformations that require intermediate variables temporary (or scratch) variables can be used  Any variable name that begins with a # is treated as a temporary variable  These variables are discarded at the end of a series of transformations when SPSS encounters an EXECUTE command or other commands that read the data Using Temporary Variables 6
  7. 7.  This example syntax creates a variable called var1 and then computes the factorial (n!) DATA LIST FREE / var1. BEGIN DATA 1 2 3 4 5 END DATA. COMPUTE factor=1. LOOP #tempvar=1 TO var1. -COMPUTE factor=factor * #tempvar. END LOOP. EXECUTE.  A temporary variable tempvar is used to do the calculation: n*(n- 1)*(n-2)*(n-3) * ...*1  This is done within a LOOP – END LOOP structure Example using Temporary variables 7
  8. 8.  SPSS is designed to minimise the number of times it has to read the data, however each time an EXECUTE command is executed through syntax the data is read.  Statistical and Charting procedures always read the data but most transformation commands do not require a separate data pass  Creating command syntax from pasting different procedures can include a lot of extra EXECUTE commands which can increase processing time Use EXECUTE sparingly 8
  9. 9.  In most cases virtually all of the auto-generated EXECUTE commands can be removed, and this will speed up processing  To turn off the automatic, immediate execution of transformations and the associated pasting of EXECUTE commands:  Edit -> Options -> Data tab: Calculate values before used. Use EXECUTE sparingly 9
  10. 10.  Instead of working with very large syntax files with 1000’s of lines of code, break down your syntax file into a number of standalone files  You might have a syntax separate file for: • Preparing and standardising data • Merging data files • Performing tests on data • Running reports  Using the INSERT command and a master command file that specifies all of the other command files you can partition all your tasks into separate command files Using the INSERT command 10
  11. 11.  The INSERT command provides a method for linking multiple syntax files together making it possible to reuse blocks of command syntax Using the INSERT command 11
  12. 12. Talk to us  +44 (0)208 757 8820 (UK) +353 (0)1 415 0234 (IRL) For more Tech Tips visit