views:

380

answers:

3

Is there a "native" SPSS way to loop through some variable names? All I want to do is take a list of variables (that I define) and run the same procedure for them:

pseudo-code - not really a good example, but gets the point across...

for i in varlist['a','b','c']
do
  FREQUENCIES VARIABLES=varlist[i] / ORDER=ANALYSIS.
end

I've noticed that people seem to just use R or Python SPSS plugins to achieve this basic array functionality, but I don't know how soon I can get those configured (if ever) on my installation of SPSS.

SPSS has to have some native way to do this...right?

A: 

Here's a page from UCLA's Academic Technology Services that describes looping over lists of variables. Quote,

"Because we are looping through more than one variable, we will need to use Python."

In my experience, UCLA ATS is probably the site with the best coverage of all of the major statistical computing systems. If they say you need Python... you probably need Python.

Er... sorry for being that guy, but maybe it's time to switch to a different stats system.

Matt Parker
Well, I have SAS too, but SPSS seemed to be better for the type of mostly point-and-click stats I was doing. Thanks for the advice :) Maybe I'll just figure out the SAS code for this task...
chucknelson
A: 

I haven't used SPSS macros very much, but maybe they can get you where you need to be? Check out this site for some examples:

http://spsstools.net/Macros.htm

Also, the SPSS Data Management book may be helpful as well.

Lastly, if memory serves, I think the problem may even be the main example of how to leverage Python inside of SPSS syntax. I have only used Python and SPSS a few times, but it is very handy to have that language accessible if need be.

HTH

Btibert3
A: 

It's more efficient to do all these frequencies on one data pass, e.g., FREQUENCIES a to c. but Python lets you do looping and lots of other control flow tricks. begin program. import spss for v in ['a','b','c']: spss.Submit("FREQUENCIES " + v) end program.

Using Python requires installing the (free) Python plugin available from SPSS Developer Central, www.spss.com/devcentral.

You can, of course, use macros for this sort of things, but Python is a lot more powerful and easier once you get the hang of it.

Jon Peck