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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
* Two string variables (problem and race) contain a variable number of comma separated numbers. How can I parse this info?.

*(A) by Raynald Levesque 2002/03/22.


* Sample data file.
DATA LIST LIST /sex(F1.0) str(A20).
BEGIN DATA
1,"A" 
2,"A,B,C,D"
1,"A,C,E,F,J,K,L,P" 
1,"F,J,K"
END DATA.
LIST.

SET MPRINT=no.
* Define a macro to do the job.
*///////////////////.
DEFINE !parse (var=!TOKENS(1) /nbval=!TOKENS(1))
COMPUTE !var=CONCAT(RTRIM(!var),',').
STRING #str(A8).
VECTOR !var (!nbval A3).
COMPUTE #beg=1.
LOOP #cnt=1 TO !nbval.
+COMPUTE #str=SUBSTR(!var,#beg).
+COMPUTE #end=INDEX(#str,',')-1.
+DO IF #end=-1.
+ BREAK.
+END IF.
+COMPUTE !var(#cnt)=SUBSTR(#str,1,#end).
+COMPUTE #beg=#beg+#end+1.
END LOOP IF #end=-1.
EXECUTE.
!ENDDEFINE.
*///////////////////.

SET MPRINT=yes.
* Now call the macro.
!parse var=str nbval=10.
SET MPRINT=no.

* To know how many selected A and C:.
STRING str11(A3).
IF (INDEX(str,'A')>0 & INDEX(str,'C')>0) str11='AC'.

* Create table of frequencies.
TABLES
  /FORMAT BLANK MISSING('')  /MRGROUP  $resp  str1 TO str11
  /GBASE=CASES
  /TABLE=$resp.

*Create crosstab of response vs sex.



* Multiple Response Tables.
TABLES
  /FORMAT BLANK MISSING('')  /MRGROUP  $str  str1 str10 str11 str2 str3 str4
  str5 str6 str7 str8 str9
  /GBASE=CASES
  /TABLE=$str BY sex .