1

如果spss中有任何命令,是否可以使用嵌套?例如

 if any(1, a to c) and if (1, s to x) xx=1.
4

2 回答 2

5

当然可以,但是您的语法不太正确。if (any(1, a to c) and any(1, s to x)) xx=1。

if 表达式可以任意复杂,但必须是表达式。if 部分是一个语句。

高温高压

于 2011-12-03T04:24:42.417 回答
0

只是为了提供一个澄清嵌套部分的答案,这是一个使用do if而不是if.

do if any(1, a to c).
    do if any(1, s to x).
        compute xx=1.
    end if.
end if.

a此代码查找在任何变量上至少有一次得分为 1 的行c。仅在这些行中,它会找到在任何变量上至少有一次得分为 1 的sx。通过第一个语句并随后通过第二个语句的行被分配xx=1

它产生与以下相同的结果:

if any(1, a to c)andany(1, s to x) xx=1.

但是,以下会产生不同的结果:

if any(1, a to c) xx=1.
if any(1, s to x) xx=1.

这本质上与在 2 个条件语句之间使用or的含义相同

if any(1, a to x)orany(1, s to x) xx=1.

于 2018-08-11T07:37:37.707 回答