SPSS宏中的变量标签 [英] Variable labels in SPSS Macro
问题描述
我是SPSS宏语法的新手,在尝试基于简单循环计数器标记变量时遇到了很多困难.这是我尝试做的事情:
I'm new to the SPSS macro syntax and had a hard time trying to label variables based on a simple loop counter. Here's what I tried to do:
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.
但是,当我运行此命令时,会收到以下警告:
However, when I run this, I get the following warnings:
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的值为'.
Indeed the label is then only 'Indexvar has value '.
使用在打印时开启mprint设置"后,将打印以下代码:
Upon using "set mprint on printback on", the following code was printed:
variable labels indexvar_value_1_ind 'Indexvar has value ' '1'
所以看来SPSS似乎以某种方式删除了应该将两个字符串连接在一起的"+",但是为什么呢?
So it appears that SPSS seems to somehow remove the "+" which is supposed to concatenate the two strings, but why?
宏的其余部分工作正常,只是变量标签命令引起了问题.
The rest of the macro worked fine, it's only the variable labels command that's causing problems.
推荐答案
尝试:
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(零).以这种方式只使用一个计算,不仅减少了代码行,而且还使转换效率更高/运行起来更快.
Where the right hand side of the COMPUTE
equation evaluates to equal TRUE
a 1 (one) is assigned else if FALSE
a 0 (zero) is assigned. Using just a single compute in this way not only reduce the lines of code, it will also make the transformations more efficient/quicker to run.
这篇关于SPSS宏中的变量标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!