|
I want to use SPSS 15 to generate separate Custom
Tables that have identical column headings but different row variables. Here’s
an example of how that would be done by copying and pasting the syntax for the
first table and changing the variable name of the row variable in the syntax for
the second table: * Custom Tables. CTABLES /VLABELS VARIABLES=Acme qs1
DISPLAY=DEFAULT /TABLE qs1 BY Acme [COUNT F40.0,
COLPCT.COUNT PCT40.1] /CATEGORIES VARIABLES=Acme qs1 ORDER=A
KEY=VALUE EMPTY=INCLUDE TOTAL=YES
POSITION=BEFORE. * Custom Tables. CTABLES /VLABELS VARIABLES=Acme qs2
DISPLAY=DEFAULT /TABLE qs2 BY Acme [COUNT F40.0,
COLPCT.COUNT PCT40.1] /CATEGORIES VARIABLES=Acme qs2 ORDER=A
KEY=VALUE
EMPTY=INCLUDE TOTAL=YES POSITION=BEFORE. Note
the column variable (Acme) is the same for both tables. The row variable in the
first syntax (qs1) has been changed to qs2 to generate the table designated in
the second syntax. The row variable name is the only difference between the two
syntax statements. I
need to do this for dozens of contiguous row variables so I want to avoid
cutting and pasting and changing the row variable names by hand. Is there any
way this can be done using, for example, a TO statement to identify the
contiguous row variables? Thanks. |
|
Dear James,
If I understand you correctly, a basic macro index loop should do the trick. The loop variable [!lv] will first assume the value [1], rendering the concatenation of [qs] and [!lv] [qs1]. Then [!lv] will take on [2], so [!concat("qs",!lv)] will become [qs2]. And so on. See the code below. HTH! Ruben van den Berg Methodologist TNS NIPO P: +31 20 522 5738 *Generate test data. cd 'c:\temp'. input program. loop id=1 to 100. end case. end loop. end file. end input program. do repeat v=acme qs1 to qs25. compute v=rnd(rv.uni(-.5,3.5)). end repeat. value labels acme qs1 to qs25 0"Yes"1"No"2"Don't know"3"Not applicable". variable level acme qs1 to qs25 (nom). execute./*Not necessary, but now you can actually see the test data generated. *Macro definition, tells SPSS what to do if [!tables] is encountered anywhere. define !tables() !do !lv=1 !to 25 CTABLES /VLABELS VARIABLES=Acme !concat("qs",!lv) DISPLAY=DEFAULT /TABLE !concat("qs",!lv) BY Acme [COUNT F40.0, COLPCT.COUNT PCT40.1] /CATEGORIES VARIABLES=Acme !concat("qs",!lv) ORDER=A KEY=VALUE EMPTY=INCLUDE TOTAL=YES POSITION=BEFORE. !doend !enddefine. *Macro call, will produce the 25 custom tables. !tables. Date: Mon, 24 May 2010 11:03:37 -0500 From: [hidden email] Subject: Syntax to Generate Separate Custom Tables Using Constant Column Variable and Different Row Variables To: [hidden email] I want to use SPSS 15 to generate separate Custom Tables that have identical column headings but different row variables. Here’s an example of how that would be done by copying and pasting the syntax for the first table and changing the variable name of the row variable in the syntax for the second table: * Custom Tables. CTABLES /VLABELS VARIABLES=Acme qs1 DISPLAY=DEFAULT /TABLE qs1 BY Acme [COUNT F40.0, COLPCT.COUNT PCT40.1] /CATEGORIES VARIABLES=Acme qs1 ORDER=A KEY=VALUE EMPTY=INCLUDE TOTAL=YES POSITION=BEFORE.
* Custom Tables. CTABLES /VLABELS VARIABLES=Acme qs2 DISPLAY=DEFAULT /TABLE qs2 BY Acme [COUNT F40.0, COLPCT.COUNT PCT40.1] /CATEGORIES VARIABLES=Acme qs2 ORDER=A KEY=VALUE EMPTY=INCLUDE TOTAL=YES POSITION=BEFORE.
Note the column variable (Acme) is the same for both tables. The row variable in the first syntax (qs1) has been changed to qs2 to generate the table designated in the second syntax. The row variable name is the only difference between the two syntax statements.
I need to do this for dozens of contiguous row variables so I want to avoid cutting and pasting and changing the row variable names by hand. Is there any way this can be done using, for example, a TO statement to identify the contiguous row variables?
Thanks. New Windows 7: Find the right PC for you. Learn more. |
| Free forum by Nabble | Edit this page |
