3

I am working in SPSS and have a large number of variables, call them v1 to v7000.

I want to perform a series of "complex operations" on each variable to create a new set of variables: t1 to t7000.

For the sake of illustration, let's just say the "complex operation" is to have t1 be the square of v1, t2 be the square of v2, etc.

My thought is to write some code like this.

do repeat t=t1 to t7000
compute t = v*v;
end repeat.

But, I don't think this will work.

What is the right way to do this? Thanks so much in advance.

al wong
  • 31
  • 2
  • 7000 variables??? Perhaps an array is in order? – Mitch Wheat Aug 06 '11 at 03:15
  • Thank you for your swift reply. I will look into how to use arrays in SPSS and report back if I find success. :-) – al wong Aug 06 '11 at 03:37
  • Oh, and incidentally, regarding your question, it *is* 7000 variables (7368 to be exact). Though, perhaps even more staggering is that it is 23000 cases. :-) It is a massive database research project. Thanks again. – al wong Aug 06 '11 at 03:46

1 Answers1

5

Multiple stand-in variables can be specified on a DO REPEAT command.

do repeat t = t1 to t7000
 /v = v1 to v7000.
compute t = v**2.
end repeat.
djhurio
  • 5,437
  • 4
  • 27
  • 48
  • Would you provide more context for this example? Do the variables v1 to v7000 have to be initialized? Does this work if the variables have some arbitrary naming that is not neatly indexed like in this example? – PaulB May 03 '22 at 14:32
  • I am not using SPSS Statistics any more. But according to the reference manual. _A replacement variable list (`t1 to t7000` and `v1 to v7000` in the example) can include either new or existing variables. Keyword TO can be used to name consecutive existing variables and to create a set of new variables._ Please refer to the IBM SPSS Statistics Command Syntax Reference for more details (Chapter 85. DO REPEAT-END REPEAT). https://www.ibm.com/support/pages/ibm-spss-statistics-26-documentation#en – djhurio May 04 '22 at 15:47