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
37
38
39
40
41
42
43
44
* Make dummy data file for illustration purposes.
NEW file.
INPUT PROGRAM.
SET SEED=987654321.
LOOP ID=1 to 100.
	COMPUTE grade=6+trunc(uniform(7)).
	END CASE.
end loop.
end file.
end input program.
execute.

SET MPRINT=on.

*////////////////////////////////.
DEFINE corpsum (grades=!CMDEND)
COMPUTE filt=0.
!do !n !in (!grades)
	!if (!n !ne '0') !then
		if (grade=!n) filt=1 .
	!else
		execute .
		filter by filt .
		LIST.
* Enter here any processing you want to do.		
		recode filt (else=0) .
		execute .
	!ifend
!doend .

execute .
filter by filt .
LIST.
recode filt (else=0) .
execute .
!ENDDEFINE.
*////////////////////////////////.

* Following macro call runs analysis in cases where grades=6.
* Then on cases where grades=7 or 8.
* Then on cases where grades=9 or 10.
* etc.

corpsum grades=6 0 7 8 0 9 10 0 11 12.