简单表达式中 SPSS 逻辑运算符和字符串的错误

Errors with SPSS Logical Operators and Strings In a Simple Expression

我在实现以下功能时遇到了一些意外错误。在这个示例代码中,我有一周中几天的温度。对于这个一般化示例,我感兴趣的是确定 72,74 或 65 度的日子。作为输出,应创建一个变量,其中包含该温度范围内的星期几。另外,请注意,在这些数据中,只有 1 天属于这些温度之一。

Monday     Tuesday     Wednesday     Day of Interest    
72         78          80            
61         78          74            



Monday     Tuesday     Wednesday     Day of Interest    
72         78          80             2  
61         78          74             4

在 Whosebug 的大佬们的慷慨帮助下,我写了下面的代码,

IF (Monday = 65 OR 72 OR 74) Day_Of_Interest = 2.
IF (Tuesday= 65 OR 72 OR 74) Day_Of_Interest = 3.
IF (Wednesday = 65 OR '72' OR 74) Day_Of_Interest = 4.
IF (Thursday = 65 OR 72 OR 74) Day_Of_Interest = 5.

但遗憾的是 returns 一个错误:

 IF A relational operator may have two numeric operands or two character 
string operands. To compare a character string to a numeric quantity,
consider using the STRING or NUMBER function.'

我尝试将代码更改为类似于“65”或“72”,但这产生了另一个错误。如果有人对如何使这项工作有任何想法,我将不胜感激。我知道上面的例子不是最好的,但它是我能想到的最好的。如果您需要更多详细信息,我将非常乐意提供帮助。非常感谢你的帮助!

编辑:我应该说如果我只是在寻找一个数字,比如 72,这段代码确实有效。

使用 IF 进行多重比较只会这样工作:

IF (Monday = 65 OR Monday = 72 OR Monday = 74) Day_Of_Interest = 2.

但在这种情况下 ANY 函数会更有用:

IF any(Monday, 65, 72, 74) Day_Of_Interest = 2.

现在如果你想在所有工作日都这样做,你可以使用一个循环:

do repeat day=Sunday Monday Tuesday Wednesday Thursday Friday Saturday
    /Dnum=1 2 3 4 5 6 7.
    IF any(day, 65, 72, 74) Day_Of_Interest = Dnum.
end repeat.
exe.