1

In SPSS, I have a variable, CumulLast, which takes on values between 1 and 20. I have another family of variables, of the form Status.X, where X takes on values between 1 and 20 (e.g. Status.1, Status.2, Status.3, are all variables in my dataset). What I'm trying to do is to create a new variable, StatusLast, whose value is the value of Status.Y, where Y is the value stored in each row's CumulLast. For example, if in row 1, CumulLast is 5, I want row 1's StatusLast value to equal the value of Status.5 in row 1.

I've tried recoding CumulLast into StatusCumulLast, with values of the form Status.X (i.e. the variable names I want), but I don't know where to go from here, and if I can skip this step.

theChemist
  • 21
  • 3

2 Answers2

1

Ended up doing this later on:

VECTOR vecStatus = Status.1 to Status.20.
COMPUTE StatusLast = vecStatus(CumulLast).
theChemist
  • 21
  • 3
0

This loops through the variables and puts the right value in StatusLast based on the value in CumulLast:

do repeat vl = 1 to 20 / vr = Status.1 to Status.20 .
if CumulLast = vl StatusLast = vr.
end repeat.
exe.
eli-k
  • 10,898
  • 11
  • 40
  • 44
  • 1
    Thanks @eli-k, much appreciated. I discovered VECTOR some time later, and ended up using that (i.e. doing VECTOR vecStatus = Status.1 TO Status.20, then indexing into vecStatus with the numbers). – theChemist Jul 13 '23 at 16:58
  • Sounds like a good solution (if not better) - you should post it as an additional answer here, and possibly mark *that* as your solution. – eli-k Jul 14 '23 at 11:21