How can I loop through variables in SPSS? I want to avoid code duplication

后端 未结 7 1731
失恋的感觉
失恋的感觉 2021-01-03 02:31

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:

<
7条回答
  •  长情又很酷
    2021-01-03 03:11

    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.

提交回复
热议问题