2

我不认为 SPSS 宏可以返回值,所以不是像VIXL3 = !getLastAvail target=VIX level=3我想的那样分配一个值,我需要做这样的事情:

/* computes last available entry of target at given level */
define !compLastAvail(name !Tokens(1) /target !Tokens(1) /level !Tokens(1))
   compute tmpid= $casenum.
   dataset copy tmpset1.
   select if not miss(!target).
   compute !name= lag(!target, !level).
   match files /file= * /file= tmpset1 /by tmpid.
   exec.
   delete variables tmpid.
   dataset close tmpset1.
!enddefine.

/* compute last values */

!compLastAvail name="VIXCL3" target=VIXC level=3.

compute !name = ...就是问题所在。

这应该如何正确完成?以上返回:

>Error # 4285 in column 9.  Text: VIXCL3
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>Execution of this command stops.
4

1 回答 1

2

当您将标记传递给宏时,它们会被逐字解释。所以当你指定

!compLastAvail name="VIXCL3"

它作为 传递给相应的compute语句"VIXCL3",而不仅仅是一个不带引号的变量名(例如VIXCL3)。

另外两条一般性建议;

  1. 如果您set mprint on在执行宏之前执行该命令,您将看到您的令牌是如何传递给宏的。在这种情况下,如果您采取了该步骤,您将看到有问题的计算语句和错误消息。

  2. Sometimes you do what to use quotation marks in tokens, and when that is the case the string commands !QUOTE and !UNQUOTE come in handy.

于 2012-01-13T23:27:00.883 回答