SPSS macros are programs to facilitate data processing and analysis in SPSS Statistics statistical package. A user who knows SPSS command language – “syntax”, - is able to write macros for tasks necessary for him or her. How to do it is described in the syntax Guide (“Command Syntax Reference” = “Syntax Reference Guide”) appended to SPSS. Those who study programming capabilities of SPSS can be recommended a book by Raynald Levesque, SPSS Programming and Data Management., SPSS Inc (download 2nd edition where macros are described best). Programming and macros are well described also in a special reference by SPSS Inc (download).

Those who aren’t going to write macros but are willing to use them should be enough to know that a macro consists of the body and the macro call. The body is the program itself; it begins with the word define and ends with the word !enddefine. Macros that you can download from our site place their body in files with extensions SPS. The macro call is, in principle, a command like any command of SPSS syntax. It consists of the command name which is the name of the given macro, and arguments, i.e. input parameters which values must be specified by the user. Macro call and full description of each of the local macros you’ll find in a corresponding file with the extension DOC. Examples are also there.

Almost always I write macros in the way the arguments present themselves as subcommands similar to subcommands of usual SPSS commands. Each subcommand is to be written after slash (/). Unlike subcommands at usual commands, in case of a macro the subcommand that you’ll put first must go without slash:

!macro vars = v1 v2
       /regist = YES.

In this example, there are 2 subcommands and the first mentioned is without slash. In most cases the order of subcommands doesn’t matter, and wherever it is not so I notice in the description. Specification for VARS in the above example are variable names, i.e. random input: you might have specified other variables than V1 and V2. Specification for REGIST is a keyword to be chosen from some permitted list, for example, YES and NO. Keywords in my macros should be written necessarily in capital letters. Everything else can be written in any letters. Do not abbreviate keywords or subcommand names.

How to run a macro. Open a file with a macro body, mouse-select the whole body and press Run. This isn’t run of the macro yet but reading it into the “memory” of SPSS. Same macro is enough to be read once during the whole session of work with SPSS. In a Syntax window (I recommend another one, not that where the body has been opened, for avoidance to harm it by chance), prepare the macro call. You can write it, or copy it from the description document and change input there how you need. Then select the macro call or simply put the cursor on it, and press Run.

Error messages. In some of the macros, I provided special messages from macro’s side about typical mistakes that you can make when specifying input. However none of the macros track all possible violations of specification rules told in a description. Usually incorrect input will cause error messages from SPSS side but it is not always the case because specification that is incorrect from the given macro’s point of view is not necessarily incorrect from the SPSS syntax rules’ point of view. To avoid mistaken specifications, read thoughtfully the discription of a given macro.

Protected directory. Some of the macros write temporary files to hard disc. If you don't have Administrator rights of your computer, it may cause error saying, among all, that you may be trying to write to a protected directory. To solve it, issue command prior running the macro: CD 'myfolder'., where 'myfolder' is the path/name of a folder where you are allowed to save files to.

Defaults. Descriptions let know of subcommands that can be omitted or unspecified. Unspecification, i.e. writing a subcommand with nothing after “=”, is usually the same as omitting the subcommand but is not always permitted.

String input. Specifications that are strings (text) in SPSS – for instance, descriptive labels for variables or values – should be put according to usual SPSS rules: in quotes or apostrophes, no matter. If the string itself contains apostrophes as its part then use quotes. If the string contains quotes as its part then use apostrophes.

Modifying body. It is unlikely that you will need to change something inside the macro body: I brought maximum parameters outside as arguments that you can manipulate. I preset such things as number of cycles (loops) in the body “in stockpile”. But if you need even more cycles then find the SET command in the body and put there the amount. And if you are going to modify (develop) my macros or have a counsel for that please enlighten, for I could be interested with your ideas.