Thread: syntax: number of occurence of a times b

1. syntax: number of occurence of a times b

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.

2. Re: syntax: number of occurence of a times b

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.``````

3. Re: syntax: number of occurence of a times b

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.``````

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts