How to compute a new variable if at least 2 items are endorsed?

#1
I need to be able to compute newvar=1 if any two/at least two conditions in a list are met. Basically, how do I modify an OR statement to make it so the variable is computed only if at least 2 of the criteria are met.

This is what I have thus far:

IF((p_ri4 >1 OR (p_ri20 >2 OR p_ri26 >1) OR p_ri1 >2 OR p_ri24 >2 OR p_ri8 >2 OR p_ri21 >2)) p_ridx =1

Any help is much appreciated!
 

Karabiner

TS Contributor
#2
A very crude solution:

COMPUTE newvar = 0.
EXECUTE .

IF(p_ri4 >1) newvar = newvar+1 .
EXECUTE.
IF(p_ri20 >2) newvar = newvar+1 .
EXECUTE.
IF(p_ri26 >1) newvar = newvar+1 .
EXECUTE.
(...)
IF(p_ri21 >2) newvar = newvar+1 .
EXECUTE.

IF(newvar > 1) p_ridx = 1 .
EXECUTE.
IF(newvar < 2) p_ridx = 0 .
EXECUTE.