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

后端 未结 7 1733
失恋的感觉
失恋的感觉 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:01

    Yes, SPSS can do this. Sounds like the guys at UCLA use python 'cause they know how to do it in python and not in SPSS. :)

    Let's call your variables VARA, VARB, VARC. They must be numerical (since you are doing frequencies) and they must be consecutive in your spss data file. Then you create a vector saying in effect "here is the series of variables I want to loop through".

    VECTOR VectorVar = VarA TO VarC.
    LOOP #cnt = 1 to 3 by 1.
        FREQUENCIES VARIABLES=VectorVar(#cnt) / ORDER=ANALYSIS
    ENDLOOP.
    EXECUTE.
    

    (The above has not been tested. Might be missing a period somewhere, etc.)

提交回复
热议问题