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
45
46
47
* QUESTION: .
* My variables of interest go from v191 to v247. 
* variables v191, v192 and v193 form a group.
* variables v194, v195 and v196 form another group, and so on.
* For each group, I want to list cases where the first variable of the group = 1 and the second variable=0.
* LIST is not allowed in a loop. Is there a way around?

* ANSWER by rlevesque@videotron.ca.

* Create a dummy file for illustration purposes.
NEW FILE.
INPUT PROGRAM.
NUMERIC v191 TO v247.
LOOP v1=1 TO 20.
VECTOR v=v191 TO v247.
LOOP #cnt=1 TO 57.
DO IF MODE(#cnt,3)=0.
COMPUTE v(#cnt)=UNIFORM(1).
ELSE.
COMPUTE v(#cnt)=UNIFORM(1)>.5.
END IF.
END LOOP.
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
EXECUTE.

* define a macro to do the job.
*/////////////////////////////////.
DEFINE !listvar().
FILTER OFF.
!DO !cnt=191 !TO 247 !BY 3.
FILTER OFF.
COMPUTE L=0.
!LET !a1=!CONCAT('v',!cnt).
!LET !a2=!CONCAT('v',!LENGTH(!CONCAT(!BLANKS(!cnt)," "))).
!LET !a3=!CONCAT('v',!LENGTH(!CONCAT(!BLANKS(!cnt),"  "))).
IF ( !a1=1 & !a2=0 ) L=1.
FILTER BY L.
LIST v1 !a1 !a2 !a3.
!DOEND.
!ENDDEFINE.
*/////////////////////////////////.

*Call macro.
!listvar.