SPSS: How to access values of variables, where the names of the variables I want are the values of another variable

78 Views Asked by At

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.

2

There are 2 best solutions below

0
theChemist On BEST ANSWER

Ended up doing this later on:

VECTOR vecStatus = Status.1 to Status.20.
COMPUTE StatusLast = vecStatus(CumulLast).
2
eli-k On

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.