I am trying to program a classical For/Next loop of commands within SPSS Statistics. However, the LOOP and DO REPEAT commands seem to only be used for individual cases and often just inputting data. My desired group of commands would operate on ALL of the cases in a dataset Also, LOOP and DO REPEAT do not read and execute on the dataset until the end of the LOOP or Repeat section. That won't work for me. I seem to need a different kind of looping mechanism than I can find in the manual. Within my desired loop there would be the following types of commands: COMPUTE (several of these, both numeric and string) SELECT IF ADD FILES (to save the variables I have created before I go around for my next loop). Currently, I keep getting error messages when I use the LOOP command to do this. Is there a way to do this with standard SPSS Statistics syntax? Or would I have to call out to Python or R to accomplish it? Thank you.
I'm not sure why you really need a loop - you might check out XSAVE if you are trying to create multiple files, but it is true that LOOP, DO REPEAT etc only allow casewise operations in the body.
It is very easy, though, to do loops with Python programmability using the spss.Submit apis to run commands and controlling the flow with Python looping constructs. If you want to post a more detailed description of the task, I can provide an example.
concatenate in loop 2 Answers
How to send a email in spss？ 9 Answers
Entering a date into a save file name 3 Answers