Multiple Crosstabs

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Multiple Crosstabs

Hashmi, Syed S
Hi Listers,

I have a dataset that includes sets of variables that describe different
instances of a similar event. For example, over a 6 month period a patient
may have experienced multiple episodes of a symptom such as the flu.
Therefore, there are multiple variables that code for flu_n, month_n,
duration_n, cough_n, max_temp_n for each of the different flu espisodes,
where _n is a number 1 to 10 that signifies the first 10 episodes during
the study period.

I wanted to run some crosstabs, eg. compare month of episode to the
duration of that episode, or whether there was concomitant cough during
that episode. Since there are 10 possible comparisons for each, it gets
quite tedious having to type out the code for each one separately.

I tried using DO REPEAT but that didn't work. I tried putting all the vars
in the same crosstab as shown below but that didn't work either (the
following gave me 9 comparisons instead of the 3 I wanted):

   CROSSTABS
     /TABLES= month1 month2 month3 BY cough1 cough2 cough3
     /FORMAT= AVALUE TABLES
     /CELLS= COUNT
     /COUNT ROUND CELL .

Is there a way to code it so that I do not have to keep on writing a
separate CROSSTABS code for each comparison?  Incidentally, some of my
variables are in sequence (cough1 to cough10) but there are others that
are not.  Would appreciate any help that any one can provide. Thanks a
heap in advance.

Shahrukh Hashmi
Reply | Threaded
Open this post in threaded view
|

Re: Multiple Crosstabs

Richard Ristow
At 11:33 PM 7/8/2007, Syed Hashmi wrote:

>I have a dataset that includes sets of variables that describe
>different instances of a similar event. For example, over a 6 month
>period a patient may have experienced multiple episodes of a symptom
>such as the flu. There variables that code for flu_n, month_n,
>duration_n, cough_n, max_temp_n for each of the flu episodes, where _n
>is a number 1 to 10 that signifies the first 10 episodes during the
>study period.
>
>I wanted to run some crosstabs, eg. compare month of episode to the
>duration of that episode, or whether there was concomitant cough
>during that episode.
>
>I tried using DO REPEAT but that didn't work.

No, it won't. DO REPEAT only works within a transformation program or
INPUT PROGRAM; it won't loop over procedures, like several CROSSTABS.

You can use a macro or Python loop, but I don't think you need to,
here.

>I tried putting all the vars in the same crosstab as shown below, but
>that gave me 9 comparisons instead of the 3 I wanted:
>
>    CROSSTABS
>      /TABLES= month1 month2 month3 BY cough1 cough2 cough3
>      /FORMAT= AVALUE TABLES
>      /CELLS= COUNT
>      /COUNT ROUND CELL .
>
>Is there a way to code it so that I do not have to keep on writing a
>separate CROSSTABS code for each comparison?

Here's one, though it may count as tedious, especially with 10 or more
pairs. Unfortunately, variables in sequence won't help. Not tested:

.   CROSSTABS
       /TABLES= month1 BY cough1
               /month2 BY cough2
               /month3 BY cough3
       /FORMAT= AVALUE TABLES
       /CELLS= COUNT
       /COUNT ROUND CELL .

Or, you could unroll your data to 'long' form, with each incident in a
separate record. That could be useful, because you could tabulate all
incidents of the same kind, regardless which sequence they fell in
within the patient.
===========================================
Here's a demo. This is SPSS 15 draft output (WRR-not saved separately):

Original method:
................
|-----------------------------|---------------------------|
|Output Created               |09-JUL-2007 00:51:33       |
|-----------------------------|---------------------------|
PATIENT MONTH1 COUGH1 MONTH2 COUGH2

    01       3      1      3      3
    02       1      1      1      3
    03       3      3      3      2
    04       3      3      2      2
    05       1      2      2      3
    06       2      3      3      2
    07       1      3      1      3
    08       3      3      3      3
    09       1      3      2      2
    10       1      2      2      2
    11       2      1      3      3
    12       2      2      2      1
    13       1      2      3      1
    14       3      3      3      2
    15       1      1      1      3

Number of cases read:  15    Number of cases listed:  15


CROSSTABS
    /TABLES = MONTH1 BY COUGH1
             /MONTH2 BY COUGH2
    /CELLS  = COUNT ROWPERCENT.

Crosstabs
|-----------------------------|---------------------------|
|Output Created               |09-JUL-2007 00:51:33       |
|-----------------------------|---------------------------|
Case Processing Summary [suppressed]

MONTH1 * COUGH1 Crosstabulation
|------|-|---------------|-----------------|------|
|      | |               |COUGH1           |Total |
|      | |               |-----|-----|-----|------|
|      | |               |1    |2    |3    |1     |
|------|-|---------------|-----|-----|-----|------|
|MONTH1|1|Count          |2    |3    |2    |7     |
|      | |---------------|-----|-----|-----|------|
|      | |% within MONTH1|28.6%|42.9%|28.6%|100.0%|
|      |-|---------------|-----|-----|-----|------|
|      |2|Count          |1    |1    |1    |3     |
|      | |---------------|-----|-----|-----|------|
|      | |% within MONTH1|33.3%|33.3%|33.3%|100.0%|
|      |-|---------------|-----|-----|-----|------|
|      |3|Count          |1    |0    |4    |5     |
|      | |---------------|-----|-----|-----|------|
|      | |% within MONTH1|20.0%|.0%  |80.0%|100.0%|
|------|-|---------------|-----|-----|-----|------|
|Total   |Count          |4    |4    |7    |15    |
|        |---------------|-----|-----|-----|------|
|        |% within MONTH1|26.7%|26.7%|46.7%|100.0%|
|--------|---------------|-----|-----|-----|------|

MONTH2 * COUGH2 Crosstabulation
|------|-|---------------|------------------|------|
|      | |               |COUGH2            |Total |
|      | |               |-----|-----|------|------|
|      | |               |1    |2    |3     |1     |
|------|-|---------------|-----|-----|------|------|
|MONTH2|1|Count          |0    |0    |3     |3     |
|      | |---------------|-----|-----|------|------|
|      | |% within MONTH2|.0%  |.0%  |100.0%|100.0%|
|      |-|---------------|-----|-----|------|------|
|      |2|Count          |1    |3    |1     |5     |
|      | |---------------|-----|-----|------|------|
|      | |% within MONTH2|20.0%|60.0%|20.0% |100.0%|
|      |-|---------------|-----|-----|------|------|
|      |3|Count          |1    |3    |3     |7     |
|      | |---------------|-----|-----|------|------|
|      | |% within MONTH2|14.3%|42.9%|42.9% |100.0%|
|------|-|---------------|-----|-----|------|------|
|Total   |Count          |2    |6    |7     |15    |
|        |---------------|-----|-----|------|------|
|        |% within MONTH2|13.3%|40.0%|46.7% |100.0%|
|--------|---------------|-----|-----|------|------|


'Unroll' data:
..............
VARSTOCASES
  /MAKE MONTH FROM MONTH1 MONTH2
  /MAKE COUGH FROM COUGH1 COUGH2
  /INDEX = Episode(2)
  /KEEP =  PATIENT
  /NULL = DROP
  /COUNT = NoEpisod "No. of episodes for this patient" .


Variables to Cases
|----------------------------|---------------------------|
|Output Created              |09-JUL-2007 00:51:35       |
|----------------------------|---------------------------|
[Unroll]

Generated Variables
|--------|---------------|
|Name    |Label          |
|--------|---------------|
|NoEpisod|No. of episodes|
|        |for this       |
|        |patient        |
|--------|---------------|
|Episode |<none>         |
|--------|---------------|
|MONTH   |<none>         |
|--------|---------------|
|COUGH   |<none>         |
|--------|---------------|

Processing Statistics
|-------------|-|
|Variables In |5|
|Variables Out|5|
|-------------|-|


LIST.

List
|-----------------------------|---------------------------|
|Output Created               |09-JUL-2007 00:51:35       |
|-----------------------------|---------------------------|
[Unroll]

PATIENT NoEpisod Episode MONTH COUGH

    01        2        1     3     1
    01        2        2     3     3
    02        2        1     1     1
    02        2        2     1     3
    03        2        1     3     3
    03        2        2     3     2
    04        2        1     3     3
    04        2        2     2     2
    05        2        1     1     2
    05        2        2     2     3
    06        2        1     2     3
    06        2        2     3     2
    07        2        1     1     3
    07        2        2     1     3
    08        2        1     3     3
    08        2        2     3     3
    09        2        1     1     3
    09        2        2     2     2
    10        2        1     1     2
    10        2        2     2     2
    11        2        1     2     1
    11        2        2     3     3
    12        2        1     2     2
    12        2        2     2     1
    13        2        1     1     2
    13        2        2     3     1
    14        2        1     3     3
    14        2        2     3     2
    15        2        1     1     1
    15        2        2     1     3


Number of cases read:  30    Number of cases listed:  30


CROSSTABS
    /TABLES = MONTH  BY COUGH BY Episode
    /CELLS  = COUNT ROWPERCENT.

Crosstabs
|-----------------------------|---------------------------|
|Output Created               |09-JUL-2007 00:51:35       |
|-----------------------------|---------------------------|
[Unroll]

Case Processing Summary
|---------------|----------------------------------------|
|               |Cases                                   |
|               |------------|--------------|------------|
|               |Valid       |Missing       |Total       |
|               |----|-------|------|-------|----|-------|
|               |N   |Percent|N     |Percent|N   |Percent|
|---------------|----|-------|------|-------|----|-------|
|MONTH * COUGH *|30  |100.0% |0     |.0%    |30  |100.0% |
|Episode        |    |       |      |       |    |       |
|---------------|----|-------|------|-------|----|-------|

MONTH * COUGH * Episode Crosstabulation
|-------|-----|-|--------------|------------------|------|
|Episode|     | |              |COUGH             |Total |
|       |     | |              |-----|-----|------|------|
|       |     | |              |1    |2    |3     |1     |
|-------|-----|-|--------------|-----|-----|------|------|
|1      |MONTH|1|Count         |2    |3    |2     |7     |
|       |     | |--------------|-----|-----|------|------|
|       |     | |% within MONTH|28.6%|42.9%|28.6% |100.0%|
|       |     |-|--------------|-----|-----|------|------|
|       |     |2|Count         |1    |1    |1     |3     |
|       |     | |--------------|-----|-----|------|------|
|       |     | |% within MONTH|33.3%|33.3%|33.3% |100.0%|
|       |     |-|--------------|-----|-----|------|------|
|       |     |3|Count         |1    |0    |4     |5     |
|       |     | |--------------|-----|-----|------|------|
|       |     | |% within MONTH|20.0%|.0%  |80.0% |100.0%|
|       |-----|-|--------------|-----|-----|------|------|
|       |Total  |Count         |4    |4    |7     |15    |
|       |       |--------------|-----|-----|------|------|
|       |       |% within MONTH|26.7%|26.7%|46.7% |100.0%|
|-------|-----|-|--------------|-----|-----|------|------|
|2      |MONTH|1|Count         |0    |0    |3     |3     |
|       |     | |--------------|-----|-----|------|------|
|       |     | |% within MONTH|.0%  |.0%  |100.0%|100.0%|
|       |     |-|--------------|-----|-----|------|------|
|       |     |2|Count         |1    |3    |1     |5     |
|       |     | |--------------|-----|-----|------|------|
|       |     | |% within MONTH|20.0%|60.0%|20.0% |100.0%|
|       |     |-|--------------|-----|-----|------|------|
|       |     |3|Count         |1    |3    |3     |7     |
|       |     | |--------------|-----|-----|------|------|
|       |     | |% within MONTH|14.3%|42.9%|42.9% |100.0%|
|       |-----|-|--------------|-----|-----|------|------|
|       |Total  |Count         |2    |6    |7     |15    |
|       |       |--------------|-----|-----|------|------|
|       |       |% within MONTH|13.3%|40.0%|46.7% |100.0%|
|-------|-------|--------------|-----|-----|------|------|
=======================================
APPENDIX: All code, including test data
=======================================
INPUT PROGRAM.
.  NUMERIC PATIENT (N2).
.  NUMERIC MONTH1 COUGH1 MONTH2 COUGH2 (F3).
.  VECTOR  DATUM   =  MONTH1 TO COUGH2.
.  LOOP    PATIENT =  1 TO 15.
.     LOOP #DatmIdx = 1 TO  4.
.        COMPUTE DATUM(#DatmIdx)
            = TRUNC(RV.UNIFORM(1,4)).
.     END LOOP.
.     END CASE.
.  END LOOP.
END FILE.
END INPUT PROGRAM.
LIST.

CROSSTABS
    /TABLES = MONTH1 BY COUGH1
             /MONTH2 BY COUGH2
    /CELLS  = COUNT ROWPERCENT.

DATASET NAME     TestData WINDOW=FRONT.
DATASET COPY     Unroll.
DATASET ACTIVATE Unroll   WINDOW=FRONT.


VARSTOCASES
  /MAKE MONTH FROM MONTH1 MONTH2
  /MAKE COUGH FROM COUGH1 COUGH2
  /INDEX = Episode(2)
  /KEEP =  PATIENT
  /NULL = DROP
  /COUNT = NoEpisod "No. of episodes for this patient" .

LIST.

CROSSTABS
    /TABLES = MONTH  BY COUGH BY Episode
    /CELLS  = COUNT ROWPERCENT.
Reply | Threaded
Open this post in threaded view
|

Re: Multiple Crosstabs

Hashmi, Syed S
Richard,

Thanks for the detailed reply on unrolling data. I'll give that a shot as well and try to figure out which of the two methods would be appropriate for my dataset.

- Shahrukh

________________________________

From: Richard Ristow [mailto:[hidden email]]
Sent: Mon 7/9/2007 12:03 AM
To: Hashmi, Syed S; [hidden email]
Subject: Re: Multiple Crosstabs



At 11:33 PM 7/8/2007, Syed Hashmi wrote:

>I have a dataset that includes sets of variables that describe
>different instances of a similar event. For example, over a 6 month
>period a patient may have experienced multiple episodes of a symptom
>such as the flu. There variables that code for flu_n, month_n,
>duration_n, cough_n, max_temp_n for each of the flu episodes, where _n
>is a number 1 to 10 that signifies the first 10 episodes during the
>study period.
>
>I wanted to run some crosstabs, eg. compare month of episode to the
>duration of that episode, or whether there was concomitant cough
>during that episode.
>
>I tried using DO REPEAT but that didn't work.

No, it won't. DO REPEAT only works within a transformation program or
INPUT PROGRAM; it won't loop over procedures, like several CROSSTABS.

You can use a macro or Python loop, but I don't think you need to,
here.

>I tried putting all the vars in the same crosstab as shown below, but
>that gave me 9 comparisons instead of the 3 I wanted:
>
>    CROSSTABS
>      /TABLES= month1 month2 month3 BY cough1 cough2 cough3
>      /FORMAT= AVALUE TABLES
>      /CELLS= COUNT
>      /COUNT ROUND CELL .
>
>Is there a way to code it so that I do not have to keep on writing a
>separate CROSSTABS code for each comparison?

Here's one, though it may count as tedious, especially with 10 or more
pairs. Unfortunately, variables in sequence won't help. Not tested:

.   CROSSTABS
       /TABLES= month1 BY cough1
               /month2 BY cough2
               /month3 BY cough3
       /FORMAT= AVALUE TABLES
       /CELLS= COUNT
       /COUNT ROUND CELL .

Or, you could unroll your data to 'long' form, with each incident in a
separate record. That could be useful, because you could tabulate all
incidents of the same kind, regardless which sequence they fell in
within the patient.
===========================================
Here's a demo. This is SPSS 15 draft output (WRR-not saved separately):

Original method:
................
|-----------------------------|---------------------------|
|Output Created               |09-JUL-2007 00:51:33       |
|-----------------------------|---------------------------|
PATIENT MONTH1 COUGH1 MONTH2 COUGH2

    01       3      1      3      3
    02       1      1      1      3
    03       3      3      3      2
    04       3      3      2      2
    05       1      2      2      3
    06       2      3      3      2
    07       1      3      1      3
    08       3      3      3      3
    09       1      3      2      2
    10       1      2      2      2
    11       2      1      3      3
    12       2      2      2      1
    13       1      2      3      1
    14       3      3      3      2
    15       1      1      1      3

Number of cases read:  15    Number of cases listed:  15


CROSSTABS
    /TABLES = MONTH1 BY COUGH1
             /MONTH2 BY COUGH2
    /CELLS  = COUNT ROWPERCENT.

Crosstabs
|-----------------------------|---------------------------|
|Output Created               |09-JUL-2007 00:51:33       |
|-----------------------------|---------------------------|
Case Processing Summary [suppressed]

MONTH1 * COUGH1 Crosstabulation
|------|-|---------------|-----------------|------|
|      | |               |COUGH1           |Total |
|      | |               |-----|-----|-----|------|
|      | |               |1    |2    |3    |1     |
|------|-|---------------|-----|-----|-----|------|
|MONTH1|1|Count          |2    |3    |2    |7     |
|      | |---------------|-----|-----|-----|------|
|      | |% within MONTH1|28.6%|42.9%|28.6%|100.0%|
|      |-|---------------|-----|-----|-----|------|
|      |2|Count          |1    |1    |1    |3     |
|      | |---------------|-----|-----|-----|------|
|      | |% within MONTH1|33.3%|33.3%|33.3%|100.0%|
|      |-|---------------|-----|-----|-----|------|
|      |3|Count          |1    |0    |4    |5     |
|      | |---------------|-----|-----|-----|------|
|      | |% within MONTH1|20.0%|.0%  |80.0%|100.0%|
|------|-|---------------|-----|-----|-----|------|
|Total   |Count          |4    |4    |7    |15    |
|        |---------------|-----|-----|-----|------|
|        |% within MONTH1|26.7%|26.7%|46.7%|100.0%|
|--------|---------------|-----|-----|-----|------|

MONTH2 * COUGH2 Crosstabulation
|------|-|---------------|------------------|------|
|      | |               |COUGH2            |Total |
|      | |               |-----|-----|------|------|
|      | |               |1    |2    |3     |1     |
|------|-|---------------|-----|-----|------|------|
|MONTH2|1|Count          |0    |0    |3     |3     |
|      | |---------------|-----|-----|------|------|
|      | |% within MONTH2|.0%  |.0%  |100.0%|100.0%|
|      |-|---------------|-----|-----|------|------|
|      |2|Count          |1    |3    |1     |5     |
|      | |---------------|-----|-----|------|------|
|      | |% within MONTH2|20.0%|60.0%|20.0% |100.0%|
|      |-|---------------|-----|-----|------|------|
|      |3|Count          |1    |3    |3     |7     |
|      | |---------------|-----|-----|------|------|
|      | |% within MONTH2|14.3%|42.9%|42.9% |100.0%|
|------|-|---------------|-----|-----|------|------|
|Total   |Count          |2    |6    |7     |15    |
|        |---------------|-----|-----|------|------|
|        |% within MONTH2|13.3%|40.0%|46.7% |100.0%|
|--------|---------------|-----|-----|------|------|


'Unroll' data:
..............
VARSTOCASES
  /MAKE MONTH FROM MONTH1 MONTH2
  /MAKE COUGH FROM COUGH1 COUGH2
  /INDEX = Episode(2)
  /KEEP =  PATIENT
  /NULL = DROP
  /COUNT = NoEpisod "No. of episodes for this patient" .


Variables to Cases
|----------------------------|---------------------------|
|Output Created              |09-JUL-2007 00:51:35       |
|----------------------------|---------------------------|
[Unroll]

Generated Variables
|--------|---------------|
|Name    |Label          |
|--------|---------------|
|NoEpisod|No. of episodes|
|        |for this       |
|        |patient        |
|--------|---------------|
|Episode |<none>         |
|--------|---------------|
|MONTH   |<none>         |
|--------|---------------|
|COUGH   |<none>         |
|--------|---------------|

Processing Statistics
|-------------|-|
|Variables In |5|
|Variables Out|5|
|-------------|-|


LIST.

List
|-----------------------------|---------------------------|
|Output Created               |09-JUL-2007 00:51:35       |
|-----------------------------|---------------------------|
[Unroll]

PATIENT NoEpisod Episode MONTH COUGH

    01        2        1     3     1
    01        2        2     3     3
    02        2        1     1     1
    02        2        2     1     3
    03        2        1     3     3
    03        2        2     3     2
    04        2        1     3     3
    04        2        2     2     2
    05        2        1     1     2
    05        2        2     2     3
    06        2        1     2     3
    06        2        2     3     2
    07        2        1     1     3
    07        2        2     1     3
    08        2        1     3     3
    08        2        2     3     3
    09        2        1     1     3
    09        2        2     2     2
    10        2        1     1     2
    10        2        2     2     2
    11        2        1     2     1
    11        2        2     3     3
    12        2        1     2     2
    12        2        2     2     1
    13        2        1     1     2
    13        2        2     3     1
    14        2        1     3     3
    14        2        2     3     2
    15        2        1     1     1
    15        2        2     1     3


Number of cases read:  30    Number of cases listed:  30


CROSSTABS
    /TABLES = MONTH  BY COUGH BY Episode
    /CELLS  = COUNT ROWPERCENT.

Crosstabs
|-----------------------------|---------------------------|
|Output Created               |09-JUL-2007 00:51:35       |
|-----------------------------|---------------------------|
[Unroll]

Case Processing Summary
|---------------|----------------------------------------|
|               |Cases                                   |
|               |------------|--------------|------------|
|               |Valid       |Missing       |Total       |
|               |----|-------|------|-------|----|-------|
|               |N   |Percent|N     |Percent|N   |Percent|
|---------------|----|-------|------|-------|----|-------|
|MONTH * COUGH *|30  |100.0% |0     |.0%    |30  |100.0% |
|Episode        |    |       |      |       |    |       |
|---------------|----|-------|------|-------|----|-------|

MONTH * COUGH * Episode Crosstabulation
|-------|-----|-|--------------|------------------|------|
|Episode|     | |              |COUGH             |Total |
|       |     | |              |-----|-----|------|------|
|       |     | |              |1    |2    |3     |1     |
|-------|-----|-|--------------|-----|-----|------|------|
|1      |MONTH|1|Count         |2    |3    |2     |7     |
|       |     | |--------------|-----|-----|------|------|
|       |     | |% within MONTH|28.6%|42.9%|28.6% |100.0%|
|       |     |-|--------------|-----|-----|------|------|
|       |     |2|Count         |1    |1    |1     |3     |
|       |     | |--------------|-----|-----|------|------|
|       |     | |% within MONTH|33.3%|33.3%|33.3% |100.0%|
|       |     |-|--------------|-----|-----|------|------|
|       |     |3|Count         |1    |0    |4     |5     |
|       |     | |--------------|-----|-----|------|------|
|       |     | |% within MONTH|20.0%|.0%  |80.0% |100.0%|
|       |-----|-|--------------|-----|-----|------|------|
|       |Total  |Count         |4    |4    |7     |15    |
|       |       |--------------|-----|-----|------|------|
|       |       |% within MONTH|26.7%|26.7%|46.7% |100.0%|
|-------|-----|-|--------------|-----|-----|------|------|
|2      |MONTH|1|Count         |0    |0    |3     |3     |
|       |     | |--------------|-----|-----|------|------|
|       |     | |% within MONTH|.0%  |.0%  |100.0%|100.0%|
|       |     |-|--------------|-----|-----|------|------|
|       |     |2|Count         |1    |3    |1     |5     |
|       |     | |--------------|-----|-----|------|------|
|       |     | |% within MONTH|20.0%|60.0%|20.0% |100.0%|
|       |     |-|--------------|-----|-----|------|------|
|       |     |3|Count         |1    |3    |3     |7     |
|       |     | |--------------|-----|-----|------|------|
|       |     | |% within MONTH|14.3%|42.9%|42.9% |100.0%|
|       |-----|-|--------------|-----|-----|------|------|
|       |Total  |Count         |2    |6    |7     |15    |
|       |       |--------------|-----|-----|------|------|
|       |       |% within MONTH|13.3%|40.0%|46.7% |100.0%|
|-------|-------|--------------|-----|-----|------|------|
=======================================
APPENDIX: All code, including test data
=======================================
INPUT PROGRAM.
.  NUMERIC PATIENT (N2).
.  NUMERIC MONTH1 COUGH1 MONTH2 COUGH2 (F3).
.  VECTOR  DATUM   =  MONTH1 TO COUGH2.
.  LOOP    PATIENT =  1 TO 15.
.     LOOP #DatmIdx = 1 TO  4.
.        COMPUTE DATUM(#DatmIdx)
            = TRUNC(RV.UNIFORM(1,4)).
.     END LOOP.
.     END CASE.
.  END LOOP.
END FILE.
END INPUT PROGRAM.
LIST.

CROSSTABS
    /TABLES = MONTH1 BY COUGH1
             /MONTH2 BY COUGH2
    /CELLS  = COUNT ROWPERCENT.

DATASET NAME     TestData WINDOW=FRONT.
DATASET COPY     Unroll.
DATASET ACTIVATE Unroll   WINDOW=FRONT.


VARSTOCASES
  /MAKE MONTH FROM MONTH1 MONTH2
  /MAKE COUGH FROM COUGH1 COUGH2
  /INDEX = Episode(2)
  /KEEP =  PATIENT
  /NULL = DROP
  /COUNT = NoEpisod "No. of episodes for this patient" .

LIST.

CROSSTABS
    /TABLES = MONTH  BY COUGH BY Episode
    /CELLS  = COUNT ROWPERCENT.