Table where list of variables is generated by macro
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | *** 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) '') |
Related pages
...