Tutorial sections and descriptions:
What Is an SPSS Macro?An SPSS macro functions as a “mini program” within the syntax of SPSS. These mini programs are written in a combination of a special SPSS macro language and the familiar SPSS syntax language. Similar to other programs, macros serve to “automate” a series of operations which would be much more time-consuming or complex to perform by issuing commands one step at a time. The SPSS macro language is quite flexible. Macros can conduct a whole series of analyses, make adjustments to multiple output statistics, produce multiple charts with many combinations of variables, or any number of other tasks. After a macro has been defined, written, and saved, it can be used by “Calling” it. When Might I Use an SPSS Macro?Suppose you run weekly analyses for a marketing company. Your report provides descriptive statistics and regression models to examine the impacts of several marketing campaigns on company profits. Assuming you need to run similar analyses for 12 sets of variables every week, these analyses could be performed using one of three methods. These methods and estimates of time required are as follows:
This example involves only one simple application of SPSS macros, used for a relatively straightforward task, performed once-per-week. While the time-saving potential of a well-designed macro is apparent here, it becomes even more attractive for more complex or frequent SPSS tasks (imagine the previous example, performed every day, using 100 sets of variables, and requiring subtle adjustments to multiple output statistics). There are many applications for using macros. For instance, macros can be used to conduct tests of mediation and moderation in regression, estimate path coefficients of other indirect effects, or to perform bootstrapping functions. SPSS macros are fairly easy to create if you have a fundamental understanding of SPSS syntax. There are literally thousands of ready-made macros freely available online. Raynald’s SPSS Tools site has a large collection. Using SPSS MacrosIn order to use an SPSS macro, the macro must be
Step 1: Saving SPSS Macros
Example of a macro for initial data screening:
DEFINE !screen (variables = !CMDEND) FREQUENCIES VARIABLES=!variables /STATISTICS=STDDEV MINIMUM MAXIMUM MEAN MEDIAN SKEWNESS SESKEW KURTOSIS SEKURT /HISTOGRAM NORMAL /FORMAT=LIMIT(10) /ORDER=ANALYSIS. !ENDDEFINE. Step 2: Including an SPSS Macro in a Session
For example, if a macro called “!screen” was saved on the “C drive”; in the “My Documents” folder, you could include it by using the following command in SPSS syntax:
If the macro has been saved in the same directory as other SPSS files in the open project, it can be included without including the file directory, as in:
Step 3: Calling an SPSS Macro
Example:*Call the macro and provide the variable names.
!screen variables = X1 X2 X3 X4. *Screen some more. !screen variables = Y1 Y2 Y3 Y4. Example of an SPSS macroHere is SPSS syntax that includes definition of a macro and calling the macro. This simple macro provides screening information on variables, including skew and kurtosis and the maximum and minimum values, along with a histogram showing the shape of each distribution. *Activate the data set of interest with variables X1 through X4 and Y1 through Y4.
*Create a macro for initial data screening.DEFINE !screen (myvars = !CMDEND) FREQUENCIES VARIABLES=!myvars /STATISTICS=STDDEV MINIMUM MAXIMUM MEAN MEDIAN SKEWNESS SESKEW KURTOSIS SEKURT /HISTOGRAM NORMAL /FORMAT=LIMIT(10) /ORDER=ANALYSIS. !ENDDEFINE. *Call the macro and provide the variable names. You can find more information on SPSS macros at Macro Tutorial by Raynald Levesque. More technical information from SPSS on macros and other syntax applications is available here Matthew Galen and Dale Berger, updated 21 April 2015 |
14,691 total views, 2 views today