SPSS 宏中的变量标签

Variable labels in SPSS Macro

我是 SPSS 宏语法的新手,很难尝试基于简单的循环计数器来标记变量。这是我尝试做的事情:

define !make_indicatorvars()

  !do !i = 1 !to 10.

    !let !indicvar = !concat('indexvar_value_', !i, '_ind')

    compute !indicvar = 0.
    if(indexvar = !i) !indicvar = 1.

    variable labels !indicvar 'Indexvar has value ' + !quote(!i).
    value labels !indicvar 0 "No" 1 "Yes".

  !doend

!enddefine.

但是,当我 运行 这样做时,我收到以下警告:

Warning # 207 on line ... in column ... Text: ...
A '+' was found following a text string, indicating continuation, but the next non-blank character was not a quotation mark or an apostrophe.

Warning # 4465 in column ...  Text: ...
An invalid symbol appears on the VAR LABELS command where a slash was
expected.  All text through the next slash will be be ignored.

事实上标签只是'Indexvar has value '。

使用 "set mprint on printback on" 后,打印了以下代码:

variable labels indexvar_value_1_ind 'Indexvar has value ' '1'

看来 SPSS 似乎以某种方式删除了应该连接两个字符串的“+”,但为什么呢?

宏的其余部分工作正常,只是变量标签命令导致了问题。

尝试:

variable labels !indicvar !quote(!concat('Indexvar has value ',!i)).

另请注意:

compute !indicvar = 0.
if(indexvar = !i) !indicvar = 1.

可以简化为:

compute !indicvar = (indexvar = !i).

如果 COMPUTE 等式的右侧计算结果等于 TRUE 则分配 1(一),否则如果 FALSE 分配 0(零)。以这种方式仅使用单个计算不仅减少了代码行,还将使转换更多 efficient/quicker 到 运行。

您可以考虑使用 SPSSINC CREATE DUMMIES 扩展命令。它会自动为一个变量构建一组虚拟变量,并用值或值标签标记它们。它还创建了一个列出所有变量的宏。无需枚举这些值。它为数据中的所有值创建虚拟变量。

只要安装了 Python Essentials,它就会出现在转换菜单上。下面是一个使用 Statistics 附带的员工 data.sav 文件的示例。

SPSSINC CREATE DUMMIES VARIABLE=jobcat 
ROOTNAME1=job 
/OPTIONS ORDER=A USEVALUELABELS=YES USEML=YES OMITFIRST=NO
MACRONAME1="!jobcat".