# SPSS Batch Processing Method

I have a more than 150 list of products that will be analyzed by regression method based on years. For example:

products: A,B,C ... N (150th products)

Then regression A based on month of years:

A(Jan, Feb, March, April... Dec)
B(Jan, Feb, March, April... Dec)
and so on...


Is there any method or formula to run this BATCH processing in SPSS, if there are some macros, where do I start?

Macro would be a good start. Let's use the Employee data.sav (comes with standard SPSS installation) as a start:

1. Get the regression syntax

Suppose we are going to write a macro that would regress many outcomes on the variable "Previous experience" prevexp. First, submitting one regression model first and obtain its syntax by clicking the Paste button:

REGRESSION
/MISSING LISTWISE
/STATISTICS COEFF OUTS R ANOVA
/CRITERIA=PIN(.05) POUT(.10)
/NOORIGIN
/DEPENDENT salary
/METHOD=ENTER prevexp.


Here, the dependent variable is salary. We will write a macro so that this salary slot will be replaced by different variables. This is similar to your products A, B, C, etc. (Here I am assuming your 150 products are each a variable itself. If you have a long format where all product names are stacked in one variable, this macro will not fit, you'd either modify the macro or, much simpler, use split file to split the data by product, followed by applying the regression module.)

2. Naming the macro

To call a macro, put DEFINE and !ENDDEFINE . before and after the syntax. You'd also need to name this macro as well. Let's call it ManyModel:

DEFINE ManyModels
REGRESSION
/MISSING LISTWISE
/STATISTICS COEFF OUTS R ANOVA
/CRITERIA=PIN(.05) POUT(.10)
/NOORIGIN
/DEPENDENT salary
/METHOD=ENTER prevexp.
!ENDDEFINE .


3. Macro loop

Now, we'd need to tell SPSS that there will be a list of variables that are to be put into the slot !MyProduct, the way to do that is by defining the input method right after the macro name ManyModels. There are many ways to do that (e.g. !Enclose, !Token, etc.). For details, refer to the SPSS menu. Here, I am going to use !Enclose:

DEFINE ManyModels
(MyProduct = !ENCLOSE("[","]")) .
REGRESSION
/MISSING LISTWISE
/STATISTICS COEFF OUTS R ANOVA
/CRITERIA=PIN(.05) POUT(.10)
/NOORIGIN
/DEPENDENT salary
/METHOD=ENTER prevexp.
!ENDDEFINE .


What line 2 does here is to assign a macro variable called MyProduct. The way that the user will submit the variables is by enclosing a the variables within a pair of square bracket: "[" and "]".

Next, we'll need a loop to indicate that we will swap out salary and put another dependent variable into it:

DEFINE ManyModels
(MyProduct = !ENCLOSE("[","]")) .
!DO !I !IN (!MyProduct)
REGRESSION
/MISSING LISTWISE
/STATISTICS COEFF OUTS R ANOVA
/CRITERIA=PIN(.05) POUT(.10)
/NOORIGIN
/DEPENDENT !I
/METHOD=ENTER prevexp.
!DOEND .
!ENDDEFINE .


Three things changed in the macro above, we added a macro looping line (line 3) and we also replaced salary with !I which represents each variable in the list. Lastly, we need a !DOEND to close the !DO loop. Set a point after !DOEND .

4. Evoking the macro

Submit the above command, if no error is shown, you have just stored this macro temporary in SPSS. To evoke the macro, just call its name:

ManyModels MyProduct = [salary salbegin jobtime] .
EXECUTE .


This macro should run three regressions, each using one of the three submitted variable as dependent variable.

To make the monthly loop, you can build another !DO loop such as !DO !J = 1 !TO 12 and start from there.

Now that the technical part is over, I do agree with the comment that don't let the automatic regression models drive you. If you have 150 products, you're likely to find some of them statistically significant even none of them are. The situation can be even worse when you have 150 * 12 * number of years regression models. Just know what you're doing.

First, perhaps automating regression analysis isn't the best of all ideas. As one author put it: "some procedures require alert human participation".

Second, use Python instead of a macro. It's a million times more efficient.

A tutorial that demonstrates regression over many dependent variables is found here. You may need to tweak it a bit, though.