*** TableWhereListOfVariablesIsByMacro.SPS *(Q) Does anyone know a way to write a macro for this type of table TABLES /FORMAT BLANK MISSING('.') /TABLES ( q24 + q25 + q26 + q27) BY (LABELS) > (STATISTICS) /STATISTICS COUNT ((F5.0) 'N' ) CPCT ((PCT7.2) '%' ) . * using "q24 to q27" rather than writing them all out? * NOTE: I show the original answer then 2 generalisations. * Ray. ****************************. * (A) Original Answer posted by Burnkrant, Steve to SPSSX-L list on 2001/10/04 * (he answered his own question). ****************************. DEFINE !FREQS (). !LET !x = 'q24' !DO !i=25 !to 27 !LET !x = !CONCAT(!x,'+','q',!i) !DOEND TABLES /FORMAT BLANK MISSING('.') /TABLES (!x) BY (LABELS) > (STATISTICS) /STATISTICS COUNT ((F5.0) 'N' ) CPCT ((PCT7.2) '%' ) . !ENDDEFINE. !FREQS. ***************************. * Generalisation 1 by Ray. * Add parameters to handle any given variable and any number of consecutive variables. ***************************. SET MPRINT=no. *///////////////////////////. DEFINE !FREQS (stem=!TOKENS(1) /beg=!TOKENS(1) /end=!TOKENS(1)) !DO !i=!beg !to !end !IF (!i=!beg) !THEN !LET !x = !CONCAT(!stem,!i) !ELSE !LET !x = !CONCAT(!x,' + ',!stem,!i) !IFEND !DOEND TABLES /FORMAT BLANK MISSING('.') /TABLES (!x) BY (LABELS) > (STATISTICS) /STATISTICS COUNT ((F5.0) 'N' ) CPCT ((PCT7.2) '%' ) . !ENDDEFINE. *///////////////////////////. SET MPRINT=yes. !FREQS stem=q beg=24 end=27. * This is the result of the macro call. TABLES /FORMAT BLANK MISSING('.') /TABLES ( q24 + q25 + q26 + q27 ) BY (LABELS) > (STATISTICS) /STATISTICS COUNT ((F5.0) 'N' ) CPCT ((PCT7.2) '%' ). ***************************. * Generalisation 2 by Ray. * As above but handle any number of variables. ***************************. SET MPRINT=no. *///////////////////////////. DEFINE !FREQS (beg=!TOKENS(1) /end=!TOKENS(1) /stems=!CMDEND) !DO !i=!beg !to !end !LET !first='1' !IF (!i=!beg) !THEN !DO !stem !IN (!stems) !IF (!first='1') !THEN !LET !x = !CONCAT(!stem,!i) !LET !first='0' !ELSE !LET !x = !CONCAT(!x,' + ',!stem,!i) !IFEND !DOEND !ELSE !DO !stem !IN (!stems) !LET !x = !CONCAT(!x,' + ',!stem,!i) !DOEND !IFEND !DOEND TABLES /FORMAT BLANK MISSING('.') /TABLES (!x) BY (LABELS) > (STATISTICS) /STATISTICS COUNT ((F5.0) 'N' ) CPCT ((PCT7.2) '%' ) . !ENDDEFINE. *///////////////////////////. SET MPRINT=yes. !FREQS beg=1 end=20 stems=ci q v. * This is the result of the macro call. TABLES /FORMAT BLANK MISSING('.') /TABLES (LABELS) BY ( ci1 + q1 + v1 + ci2 + q2 + v2 + ci3 + q3 + v3 + ci4 + q4 + v4 + ci5 + q5 + v5 + ci6 + q6 + v6 + ci7 + q7 + v7 + ci8 + q8 + v8 + ci9 + q9 + v9 + ci10 + q10 + v10 + ci11 + q11 + v11 + ci12 + q12 + v12 + ci13 + q13 + v13 + ci14 + q14 + v14 + ci15 + q15 + v15 + ci16 + q16 + v16 + ci17 + q17 + v17 + ci18 + q18 + v18 + ci19 + q19 + v19 + ci20 + q20 + v20 ) /STATISTICS COUNT ((F5.0) '' ) CPCT ((PCT7.1) '')