Found a solution by myself and leaving it here if anybody needs the same thing sometime:
Code:COMPUTE myindex= 0. DO REPEAT v=var1 TO var5. DO IF v=1. COMPUTE myindex= myindex+2. END IF. DO IF v=2. COMPUTE myindex= myindex+1. END IF. END REPEAT.
I have 5 variables var1 to var5 that have either 1, 2 or 3 as value. i want to compute a kind of index that is represented by this formula:
index = (number of 1's in var1 to var5)*2 + (number of of 2's in var1 to var5)
Neither COMPUTE nor COUNT lead me to success.
Please be gracious in judging my english. (I am not a native speaker/writer.)
Found a solution by myself and leaving it here if anybody needs the same thing sometime:
Code:COMPUTE myindex= 0. DO REPEAT v=var1 TO var5. DO IF v=1. COMPUTE myindex= myindex+2. END IF. DO IF v=2. COMPUTE myindex= myindex+1. END IF. END REPEAT.
Please be gracious in judging my english. (I am not a native speaker/writer.)
Just for your future reference, the count command is used in the following way:
Code:count #a = var1 to var5 (1). count #b = var1 to var5 (2). compute myindex = (#a*2) + #b. exe.
|
|