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

查看:333
本文介绍了如何在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天全站免登陆