I need to compute the mean of a set of ratings (var V_Cr1 to V_Cr11) provided the relevant control variable (var targ_i.1 to targ_i.11) for each rating satisfies a condition (>=4 and not missing).
At first I attempted to adjust syntax that I found http://stackoverflow.com/questions/12711613/loop-through-items-and-sum-items-in-spss/12794702.
This is what I used:
COMPUTE TARG_VCs=0.
EXECUTE.
VECTOR TARG_I = targ_i.1 to targ_i.11.
VECTOR TARG_VC = V_Cr1 to V_Cr11.
LOOP #vecid = 1 to 11.
DO IF (TARG_I(#vecid) <=4 and not missing (TARG_VC((#vecid)))).
COMPUTE TARG_VCs= TARG_VCs+ TARG_VC(#vecid).
END IF.
END LOOP.
EXECUTE.
It seems to have worked to provide me a sum, although it returns zeroes instead of missing when conditions are not satisfied, I can work around that. However, from a sum to a valid mean I need a count of valid V_Cr that satisfy targ_i. My data has targ_i <=4 and not missing for which there is missing V_Cr (and the other way around, but that is accounted for in the above code), so a simple count won't do.
I figure I need either a straightforward way to compute the mean within a loop, a way to embed a count in the code (I've been trying that with no luck) or another way to have a valid denominator for my mean computation on the side. Any ideas?
New to SPSS syntax (heck, to any syntax), so this is seeming far more complicated to me than it probably needs to be, I am sure. TIA!