如何遍历 SPSS 中的变量?我想避免代码重复 [英] How can I loop through variables in SPSS? I want to avoid code duplication

查看:17
本文介绍了如何遍历 SPSS 中的变量?我想避免代码重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有原生"SPSS 方法来循环遍历某些变量名称?我想要做的就是获取一个变量列表(我定义的)并为它们运行相同的过程:

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

我注意到人们似乎只是使用 R 或 Python SPSS 插件来实现这个基本的数组功能,但我不知道我多久可以在我的 SPSS 安装中配置这些插件(如果有的话).

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 必须有一些本地方式来做到这一点......对吗?

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

推荐答案

循环变量有两种简单的解决方案(比在 SPSS 中使用 Python 更容易).

There are two easy solutions for looping through variables (easier compared to using Python in SPSS).

1) DO REPEAT-END REPEAT

缺点是您可以使用 DO REPEAT-END REPEAT 主要仅用于数据转换 - 例如 COMPUTERECODE 等.频率是不允许的.例如:

The draw back is that you can use DO REPEAT-END REPEAT mainly only for data transformations - for example COMPUTE, RECODE etc. Frequencies are not allowed. For example:

DO REPEAT R=REGION1 TO REGION5.
COMPUTE R=0.
END REPEAT.

2) DEFINE-!ENDDEFINE(宏工具)

您可以使用宏命令在变量循环中执行频率.例如:

You can do Frequencies in a loop of variables using macro command. For example:

DEFINE macdef (!POS !CHAREND('/'))
!DO !i !IN (!1)
frequencies variables = !i.
!DOEND
!ENDDEFINE.

macdef VAR1 VAR2 VAR3  /.

这篇关于如何遍历 SPSS 中的变量?我想避免代码重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆