1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
* QUESTION: How to replace missing values of scale1 TO scale17 by the mean 
* value but only when number of missing is less than 75% of scales.

* ANSWER posted to SPSSX-L on 2001/5/15 by rlevesque@videotron.ca.

* Define dummy data file for illustration purposes.
NEW file.
INPUT PROGRAM.
SET SEED=7654321.
VECTOR scale(17F8.3).
LOOP id=1 TO 50.
LEAVE id.
LOOP #id=1 TO 17.
* about 25% of scales will be missing.
	IF (UNIFORM(1)<.75) scale(#id)=TRUNC(UNIFORM(5)+.5).
END LOOP.
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
EXECUTE.

* Start the job.
COMPUTE dummy=1.
AGGREGATE OUTFILE='c:\\temp\\mydata.sav'
   /BREAK=dummy
   /mscale1 to mscale17=mean(scale1 to scale17).

MATCH FILES FILE=* /TABLE='c:\\temp\\mydata.sav' /by dummy.

DO IF (NMISS(scale1 to scale17) < 17*.25).
+  DO REPEAT orig = scale1 to scale17   /copy=mscale1 to mscale17.
+  if (missing (orig)) orig=copy.
+  END REPEAT.
END IF.
EXECUTE.