You can loop through the spell variables using the VECTOR
command.
VECTOR W1_spells = W1_spells1 TO W1_spells15.
DO REPEAT first = W1_C14_0 to W1_C14_51 /
second = W1_C14_1 to W1_C14_52 .
DO IF (SYSMIS(first) OR first<>second).
LOOP #i=1 TO 15.
DO IF (second=#i) .
COMPUTE W1_spells(#i) = W1_spells(#i) + 1.
END IF.
END LOOP.
END IF.
END REPEAT.