2

I have some variables

V1 V2 V3

which I want to give variable labels in a Loop:

variable labels V1 "Person 1".
variable labels V2 "Person 2".
...

Should be an easy thing, but as far as I could see I cannot use DO REPEAT (because it's no data transformation) but have to write a macro.

(see: How can I loop through variables in SPSS? I want to avoid code duplication)

Coming from R and STATA I really have difficulty of seeing how to start.

The answer to this question: Variable labels in SPSS Macro seems different to me since new variables are created and not existing variables relabeled.

Community
  • 1
  • 1

1 Answers1

0

If you have the SPSS Python Integration Package installed you can run a loop in Python.

The following code creates the lines variable labels V# "Person #". Where '#' is a number from 1 to 3.

BEGIN PROGRAM.
import spss

for i in range(1, 4):
    spss.Submit('variable labels V%s "Person %s".' % (i, i))
END PROGRAM.
mirirai
  • 1,365
  • 9
  • 25