* 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 .