SPSS Macros — Home
SPSS Macros are wonderful!
Macros are to syntax what syntax is to the Graphic User Interface (GUI): a big step forward.
Macro language is sort of syntax generator which can produce for you syntax, using parameters (macro arguments), conditional and looping constructs. You can treat macro also as a function by which you may generate and substitute any piece of syntax code. Macro could keep a single value to use in COMPUTE statements in many places of code, and as well it may represent thousands lines of syntax code, newly generated with the parameters you passed to it.
- reduce the number of lines of codes by up to 80–90%
- greatly simplify code maintenance
- speed up code development
- facilitate code recycling
- do things syntax can't do, for instance: create variable names "on the fly" using !CONCAT(var,!cnt).
If macro language did not exists, SPSS would have to invent it. Do try to learn macros! You will not regret it. Despite the power of macros, its language is pretty simple. You'll need to know just ten extra special instructions, like
!DO...!DOEND, and grab feeling on how it works. Learning Macros page will help you! If you need a good book (IMHO) on syntax and macros, see SPSS Programming and Data Management.
If you are not willing to study macros right now, but need to apply someone's macro to your job, see FAQ Someone posted a macro but I do not know how to use it!
Once you know macros you find many use for them. It is for this reason that most macros are in the Syntax section of this site (approx. 200 macros). Tip: to quickly find all macros, search this site for
!ENDDEFINE. I tend to store macro at Macros Library if it is "universal", that is, can be applied in lots of different situations.
I also advise you to pay attention to Kirill's SPSS macros page on this site. It contains dozens of thoroughly developed macro applications, well parametrized and documented, covering wide range of topics, from data manipulation to special statistical questions, like clustering criterion or regular clouds. You'll find there also more intro to macros and some resources collected by Kirill Orlov, macros' author.
Are Macros still relevant with the advent of Python scripts? Of course anything done with macros can be done using Python but I think macros can still be useful for many jobs. The great advantage of macro is that the are embedded into SPSS, so that they will work in almost any environment, regardless of what Integration Plugin you have installed, and which Python version it supports. To add, macro language has only minor changes over last 10 versions of SPSS, so that it has very good "backward" compatibility. So, there are very good chances that macro you sent to your colleague knowing nothing about him or her version of SPSS, operation system and plugins installed will work smoothly just like it works on your machine.