How Do I Automate Things Using Syntax?

From Q
Jump to: navigation, search

A common question asked by experienced SPSS users is "How do I automate things in Q using syntax?". While it is possible to automate things by writing code (see JavaScript), for the vast majority of situations where it is good practice to use syntax in SPSS, there are alternative methods in Q requiring no code to be written, and these alternative methods are superior: easier to do, faster to do, less chance of error.

Why experienced SPSS users assume that automation requires syntax

Using SPSS efficiently requires the user to write and maintain a lot of syntax. As a pretty general rule, the more time users spend working with syntax, the faster they are to do work in SPSS and the fewer mistakes that people make.

When an experienced SPSS user watches a novice just using point-and-click, they know that this is dangerous. They know this because in SPSS, if you use point-and-click, you:

  1. Have no way to audit projects. That is, you will often end up in a situation where you cannot figure out how a particular result in a project was computed.
  2. Have no way of updating projects with revised data.
  3. Have no way of automating processes that are done regularly (e.g., computing top 2 box scores).

Why this is a misunderstanding

When an experienced SPSS user looks at Q being demonstrated, they see that everything is point-and-click. They often ask "where is the syntax that I need for automation?". When they are told that the vast majority of Q users never write a single line of code, they interpret this as meaning that "Q is error prone, you cannot audit projects and cannot revise projects with updated data". This is a misunderstanding.

The reason that efficient use of SPSS requires the use of syntax is that SPSS when SPSS was written it was designed to work only with syntax. While you can now use your mouse and menus, the basic underlying design has not changed.

SPSS was designed in the 1960s. When it was written, almost all programs in the world were designed with the same basic model: users can either type instructions, or, write 'syntax' in a file and have the program run that syntax. However, in the 50 years since then, software design has changed a lot.

A useful analogy is writing a letter. In the 1960s, when SPSS's syntax-based user interface was designed, an executive would write a letter by dictating it to a secretary who would type it. If there were errors, it would be retyped. By the mid-1980s, the secretaries were using word processors, where they would use 'syntax' to do things like make text bold or create a table of contents. Today, almost all of the secretaries are gone. If an executive wants to write a letter, they will do so in Word (or, better yet, by email). And, the user of Word is able to automate a lot of things using many, many tools that did not exist 50 years ago. For example, they can:

  • Create templates.
  • Create style sheets.
  • Use shortcuts.
  • Take an existing document, copy it and modify it.
  • Use Add-Ins.
  • Use VBA to automate things.

Q was designed in 2005. It has the type of automation tools in it that are in modern Microsoft programs (although Microsoft uses VBA, whereas we use JavaScript). You can write 'syntax' to do many things in Q, but it should only be used very rarely (in much the same way that most people that use PowerPoint, Excel, and Word, do so efficiently without ever writing code). For example:

  • Q has a huge number of inbuilt tools for automating things that need to be automated. See Updating and Automation for more information.
  • Q has numerous tools in it to facilitate auditing your work. The consequence of this is that you can always figure out how any result has been computed in Q. There is never a need to use syntax as a way of recording what has been done in Q. See Tools for Auditing Projects for more information.

So, when an experienced SPSS user insists on understanding how to do syntax in Q, it is a not so different to an executive asking where the typing pool is located. Or, somebody trying to feed their car with hay. It is a completely understandable why the experienced SPSS user believes that syntax is at the heart of productivity. But, it is nevertheless a misunderstanding.