ROWLABELS=OPPOSITE is correct
[pspp] / tests / language / stats / ctables.at
index 432da3deb4df29a3fbce98c8c85423edf35cfe63..24c8a7a06123693f253a67a33466ddba080db718 100644 (file)
@@ -1,26 +1,12 @@
 AT_BANNER([CTABLES])
 
 dnl Features not yet tested:
-dnl - Preprocessing to distinguish categorical from scale.
-dnl - Testing details of missing value handling in summaries.
-dnl - Test WEIGHT and adjustment weights.
 dnl - Summary functions:
 dnl   * Separate summary functions for totals and subtotals.
-dnl   * )CILEVEL in summary label specification
-dnl - CATEGORIES:
-dnl   * Date values
-dnl   * THRU (numeric ranges)
-dnl   * OTHERNM
-dnl - Date/time variables and values
-dnl - Test PCOMPUTE:
-dnl   * PCOMPUTE for more than one kind of summary (e.g. [COUNT, ROWPCT]).
-dnl   * MISSING, OTHERNM
-dnl   * multi-dimensional (multiple CCT_POSTCOMPUTE in one cell)
-dnl   * dates
-dnl - Summary functions:
 dnl   * U-prefix for unweighted summaries.
 dnl   * areaPCT.SUM and UareaPCT.SUM functions.
-dnl - SPLIT FILE with SEPARATE splits
+dnl   * WEIGHT and adjustment weights.
+dnl   * details of missing value handling in summaries.
 dnl - Definition of columns/rows when labels are rotated from one axis to another.
 dnl
 dnl Not for v1:
@@ -32,6 +18,8 @@ dnl - COMPARETEST
 dnl - Summary functions:
 dnl   * .LCL and .UCL suffixes.
 dnl   * .SE suffixes.
+dnl - Summary functions:
+dnl   * )CILEVEL in summary label specification
 dnl - CATEGORIES:
 dnl   * Data-dependent sorting.
 
@@ -1610,37 +1598,267 @@ AT_CHECK([pspp ctables.sps -O box=unicode -O width=120], [0], [dnl
 AT_CLEANUP
 
 AT_SETUP([CTABLES PCOMPUTE])
+AT_KEYWORDS([postcompute])
 AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
 AT_DATA([ctables.sps],
 [[GET 'nhtsa.sav'.
 CTABLES
     /PCOMPUTE &x=EXPR([3] + [4])
     /PCOMPUTE &y=EXPR([4] + [5])
-    /PPROPERTIES &x LABEL='3+4' HIDESOURCECATS=YES FORMAT=COUNT F8.2
+    /PPROPERTIES &x LABEL='3+4' FORMAT=COUNT F8.2
     /PPROPERTIES &y LABEL=')LABEL[5]+)LABEL[6]'
-    /TABLE=qn105ba BY qns1
-    /CATEGORIES VARIABLES=qns1 [1, 2, SUBTOTAL, 3, 4, 5, &x, &y, SUBTOTAL]
+    /TABLE=qn105ba [COUNT, ROWPCT] BY qns1
+    /CATEGORIES VARIABLES=qns1 [1, 2, SUBTOTAL, 3, 4, 5, &x, &y, SUBTOTAL] TOTAL=YES
+
+* Adding HIDESOURCECATS=YES for one PPROPERTIES.
+CTABLES
+    /PCOMPUTE &x=EXPR([3] + [4])
+    /PCOMPUTE &y=EXPR([4] + [5])
+    /PPROPERTIES &x LABEL='3+4' FORMAT=COUNT F8.2
+    /PPROPERTIES &y LABEL=')LABEL[5]+)LABEL[6]' HIDESOURCECATS=YES
+    /TABLE=qn105ba [COUNT, ROWPCT] BY qns1
+    /CATEGORIES VARIABLES=qns1 [1, 2, SUBTOTAL, 3, 4, 5, &x, &y, SUBTOTAL] TOTAL=YES
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=140], [0], [dnl
+                                                                Custom Tables
+╭───────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
+│                   │                    S1. Including yourself, how many members of this household are age 16 or older?                   │
+│                   ├───────────┬───────────┬───────────┬───────────┬──────────┬──────────┬────────────┬──────────┬───────────┬────────────┤
+│                   │     1     │     2     │  Subtotal │     3     │     4    │     5    │     3+4    │    4+5   │  Subtotal │    Total   │
+│                   ├─────┬─────┼─────┬─────┼─────┬─────┼─────┬─────┼─────┬────┼─────┬────┼──────┬─────┼─────┬────┼─────┬─────┼─────┬──────┤
+│                   │     │     │     │     │     │     │     │     │     │ Row│     │ Row│      │     │     │ Row│     │     │     │      │
+│                   │Count│Row %│Count│Row %│Count│Row %│Count│Row %│Count│  % │Count│  % │ Count│Row %│Count│  % │Count│Row %│Count│ Row %│
+├───────────────────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼────┼─────┼────┼──────┼─────┼─────┼────┼─────┼─────┼─────┼──────┤
+│105b. How  Almost  │  147│30.3%│  246│50.7%│  393│81.0%│   62│12.8%│   19│3.9%│   11│2.3%│ 81.00│16.7%│   30│6.2%│   92│19.0%│  485│100.0%│
+│likely is  certain │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│it that            │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│drivers    Very    │  384│34.3%│  552│49.2%│  936│83.5%│  120│10.7%│   51│4.5%│   14│1.2%│171.00│15.3%│   65│5.8%│  185│16.5%│ 1121│100.0%│
+│who have   likely  │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│had too            │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│much to    Somewhat│  590│27.8%│ 1249│58.8%│ 1839│86.6%│  193│ 9.1%│   72│3.4%│   20│ .9%│265.00│12.5%│   92│4.3%│  285│13.4%│ 2124│100.0%│
+│drink to   likely  │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│drive              │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│safely     Somewhat│  278│26.6%│  647│61.8%│  925│88.3%│   84│ 8.0%│   32│3.1%│    6│ .6%│116.00│11.1%│   38│3.6%│  122│11.7%│ 1047│100.0%│
+│will A.    unlikely│     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│Get                │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│stopped by Very    │  141│28.5%│  290│58.7%│  431│87.2%│   41│ 8.3%│   18│3.6%│    4│ .8%│ 59.00│11.9%│   22│4.5%│   63│12.8%│  494│100.0%│
+│the        unlikely│     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+│police?            │     │     │     │     │     │     │     │     │     │    │     │    │      │     │     │    │     │     │     │      │
+╰───────────────────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴────┴─────┴────┴──────┴─────┴─────┴────┴─────┴─────┴─────┴──────╯
+
+                                                                Custom Tables
+╭─────────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────────────────────╮
+│                                         │         S1. Including yourself, how many members of this household are age 16 or older?        │
+│                                         ├───────────┬───────────┬───────────┬───────────┬────────────┬──────────┬───────────┬────────────┤
+│                                         │     1     │     2     │  Subtotal │     3     │     3+4    │    4+5   │  Subtotal │    Total   │
+│                                         ├─────┬─────┼─────┬─────┼─────┬─────┼─────┬─────┼──────┬─────┼─────┬────┼─────┬─────┼─────┬──────┤
+│                                         │     │     │     │     │     │     │     │     │      │     │     │ Row│     │     │     │      │
+│                                         │Count│Row %│Count│Row %│Count│Row %│Count│Row %│ Count│Row %│Count│  % │Count│Row %│Count│ Row %│
+├─────────────────────────────────────────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼──────┼─────┼─────┼────┼─────┼─────┼─────┼──────┤
+│105b. How likely is it that    Almost    │  147│30.3%│  246│50.7%│  393│81.0%│   62│12.8%│ 81.00│16.7%│   30│6.2%│   92│19.0%│  485│100.0%│
+│drivers who have had too much  certain   │     │     │     │     │     │     │     │     │      │     │     │    │     │     │     │      │
+│to drink to drive safely will  Very      │  384│34.3%│  552│49.2%│  936│83.5%│  120│10.7%│171.00│15.3%│   65│5.8%│  185│16.5%│ 1121│100.0%│
+│A. Get stopped by the police?  likely    │     │     │     │     │     │     │     │     │      │     │     │    │     │     │     │      │
+│                               Somewhat  │  590│27.8%│ 1249│58.8%│ 1839│86.6%│  193│ 9.1%│265.00│12.5%│   92│4.3%│  285│13.4%│ 2124│100.0%│
+│                               likely    │     │     │     │     │     │     │     │     │      │     │     │    │     │     │     │      │
+│                               Somewhat  │  278│26.6%│  647│61.8%│  925│88.3%│   84│ 8.0%│116.00│11.1%│   38│3.6%│  122│11.7%│ 1047│100.0%│
+│                               unlikely  │     │     │     │     │     │     │     │     │      │     │     │    │     │     │     │      │
+│                               Very      │  141│28.5%│  290│58.7%│  431│87.2%│   41│ 8.3%│ 59.00│11.9%│   22│4.5%│   63│12.8%│  494│100.0%│
+│                               unlikely  │     │     │     │     │     │     │     │     │      │     │     │    │     │     │     │      │
+╰─────────────────────────────────────────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴──────┴─────┴─────┴────┴─────┴─────┴─────┴──────╯
+])
+AT_CLEANUP
+
+AT_SETUP([CTABLES PCOMPUTE - OTHERNM and MISSING])
+AT_KEYWORDS([postcompute])
+AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
+AT_DATA([ctables.sps],
+[[GET 'nhtsa.sav'.
+CTABLES
+    /PCOMPUTE &x=EXPR(OTHERNM)
+    /PCOMPUTE &y=EXPR(MISSING)
+    /PPROPERTIES &x LABEL='Drivers'
+    /PPROPERTIES &y LABEL='Missing Values 2'
+    /TABLE=qn1 BY qns3a
+    /CATEGORIES VARIABLES=qn1 [OTHERNM, 5, &x, SUBTOTAL='Valid Values', MISSING, SUBTOTAL='Missing Values', &y]
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=140], [0], [dnl
+                                              Custom Tables
+╭──────────────────────────────────────────────────────────────────────────────────────────┬────────────╮
+│                                                                                          │S3a. GENDER:│
+│                                                                                          ├─────┬──────┤
+│                                                                                          │ Male│Female│
+│                                                                                          ├─────┼──────┤
+│                                                                                          │Count│ Count│
+├──────────────────────────────────────────────────────────────────────────────────────────┼─────┼──────┤
+│ 1. How often do you usually drive a car or other motor vehicle? Every day                │ 2305│  2362│
+│                                                                 Several days a week      │  440│   834│
+│                                                                 Once a week or less      │  125│   236│
+│                                                                 Only certain times a year│   58│    72│
+│                                                                 Never                    │  192│   348│
+│                                                                 Drivers                  │ 2928│  3504│
+│                                                                 Valid Values             │ 3120│  3852│
+│                                                                 Don't know               │    3│     5│
+│                                                                 Refused                  │    9│    10│
+│                                                                 Missing Values           │   12│    15│
+│                                                                 Missing Values 2         │   12│    15│
+╰──────────────────────────────────────────────────────────────────────────────────────────┴─────┴──────╯
+])
+AT_CLEANUP
+
+AT_SETUP([CTABLES PCOMPUTE - THRU])
+AT_KEYWORDS([postcompute])
+AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
+AT_DATA([ctables.sps],
+[[GET 'nhtsa.sav'.
+CTABLES
+    /PCOMPUTE &x=EXPR([1 THRU 2])
+    /PCOMPUTE &y=EXPR([3 THRU 4])
+    /PCOMPUTE &z=EXPR([5] + MISSING)
+    /PPROPERTIES &x LABEL='Frequent Drivers'
+    /PPROPERTIES &y LABEL='Infrequent Drivers'
+    /PPROPERTIES &z LABEL='Not Drivers or Missing'
+    /TABLE=qn1 BY qns3a
+    /CATEGORIES VARIABLES=qn1 [1 THRU 2, &x, 3 THRU 4, &y, SUBTOTAL='Drivers', 5, MISSING, &z]
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=140], [0], [dnl
+                                              Custom Tables
+╭──────────────────────────────────────────────────────────────────────────────────────────┬────────────╮
+│                                                                                          │S3a. GENDER:│
+│                                                                                          ├─────┬──────┤
+│                                                                                          │ Male│Female│
+│                                                                                          ├─────┼──────┤
+│                                                                                          │Count│ Count│
+├──────────────────────────────────────────────────────────────────────────────────────────┼─────┼──────┤
+│ 1. How often do you usually drive a car or other motor vehicle? Every day                │ 2305│  2362│
+│                                                                 Several days a week      │  440│   834│
+│                                                                 Frequent Drivers         │ 2745│  3196│
+│                                                                 Once a week or less      │  125│   236│
+│                                                                 Only certain times a year│   58│    72│
+│                                                                 Infrequent Drivers       │  183│   308│
+│                                                                 Drivers                  │ 2928│  3504│
+│                                                                 Never                    │  192│   348│
+│                                                                 Don't know               │    3│     5│
+│                                                                 Refused                  │    9│    10│
+│                                                                 Not Drivers or Missing   │  204│   363│
+╰──────────────────────────────────────────────────────────────────────────────────────────┴─────┴──────╯
+])
+AT_CLEANUP
+
+dnl I'm not sure that this is the correct behavior (see
+dnl https://mail.gnu.org/archive/html/pspp-users/2022-07/msg00002.html)
+dnl but at least this test will notify us if the behavior changes.
+AT_SETUP([CTABLES intersecting PCOMPUTEs])
+AT_KEYWORDS([PCOMPUTE postcompute])
+AT_DATA([ctables.sps],
+[[DATA LIST LIST NOTABLE/x y z.
+WEIGHT by z.
+FORMATS ALL (F1.0).
+VARIABLE LEVEL x y (NOMINAL).
+BEGIN DATA.
+1 4 5
+1 5 2
+1 6 9
+2 4 2
+2 5 3
+2 6 4
+3 4 1
+3 5 6
+3 6 1
+END DATA.
+
+CTABLES
+    /PCOMPUTE &a = EXPR([1] + [2])
+    /PCOMPUTE &b = EXPR([2] + [3])
+    /PCOMPUTE &c = EXPR([4] * [5])
+    /PCOMPUTE &d = EXPR([5] * [6])
+    /TABLE x BY y
+    /CATEGORIES VARIABLES=x [1, &a, 2, &b, 3]
+    /CATEGORIES VARIABLES=y [4, &c, 5, &d, 6].
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode], [0],
+[[                   Custom Tables
+╭───────────┬─────────────────────────────────────╮
+│           │                  y                  │
+│           ├─────┬─────────┬─────┬─────────┬─────┤
+│           │  4  │[4] * [5]│  5  │[5] * [6]│  6  │
+│           ├─────┼─────────┼─────┼─────────┼─────┤
+│           │Count│  Count  │Count│  Count  │Count│
+├───────────┼─────┼─────────┼─────┼─────────┼─────┤
+│x 1        │    5│       10│    2│       18│    9│
+│  [1] + [2]│    7│        .│    5│        .│   13│
+│  2        │    2│        6│    3│       12│    4│
+│  [2] + [3]│    3│        .│    9│        .│    5│
+│  3        │    1│        6│    6│        6│    1│
+╰───────────┴─────┴─────────┴─────┴─────────┴─────╯
+]])
+AT_CLEANUP
+
+AT_SETUP([CTABLES string and date and time])
+
+weight=1
+for gender in F M; do
+    for month in Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec; do
+        for wkday in Sun Mon Tue Wed Thu Fri Sat Sun; do
+           printf "$weight $gender $month $wkday\n"
+           weight=$(expr \( $weight + 3 \) % 7 + 2)
+       done
+    done
+done > ctables.txt
+
+AT_DATA([ctables.sps],
+[[DATA LIST LIST NOTABLE FILE='ctables.txt'
+    /w (F5.0) gender (A1) fmon (MONTH3) fday (WKDAY3).
+WEIGHT by w.
+VARIABLE LEVEL w (SCALE).
+VARIABLE LEVEL gender fmon fday (NOMINAL).
+VARIABLE LABEL
+  gender 'Gender'
+  fmon 'Favorite month'
+  fday 'Favorite day of the week'.
+VALUE LABELS /gender 'M' 'Male' 'F' 'Female'.
+CTABLES
+    /PCOMPUTE &q2 = EXPR(['APR' THRU 'June'])
+    /PPROPERTIES &q2 LABEL='Q2'
+    /PCOMPUTE &weekend = EXPR(['sun'] + ['Sat'])
+    /PPROPERTIES &weekend LABEL='Weekend'
+    /TABLE fmon BY gender > fday
+    /CATEGORIES VARIABLES=fmon ['JAN', 'FEB', 'Mar', SUBTOTAL="Q1",
+                                4 THRU 6, &q2,
+                               'JUL' THRU 'sep', SUBTOTAL="Q3",
+                               OTHERNM, SUBTOTAL='Q4']
+    /CATEGORIES VARIABLES=gender ['M', 'F']
+    /CATEGORIES VARIABLE=fday ['Sun', 2 THRU 6, 'Sat', &weekend] TOTAL=YES
+    /SLABELS VISIBLE=NO.
 ]])
 AT_CHECK([pspp ctables.sps -O box=unicode -O width=120], [0], [dnl
-                                                      Custom Tables
-╭────────────────────────────────────────────────────────┬─────────────────────────────────────────────────────────────╮
-│                                                        │  S1. Including yourself, how many members of this household │
-│                                                        │                     are age 16 or older?                    │
-│                                                        ├───────┬───────┬──────────┬───────┬────────┬──────┬──────────┤
-│                                                        │   1   │   2   │ Subtotal │   5   │   3+4  │  4+5 │ Subtotal │
-│                                                        ├───────┼───────┼──────────┼───────┼────────┼──────┼──────────┤
-│                                                        │ Count │ Count │   Count  │ Count │  Count │ Count│   Count  │
-├────────────────────────────────────────────────────────┼───────┼───────┼──────────┼───────┼────────┼──────┼──────────┤
-│105b. How likely is it that drivers who have Almost     │    147│    246│       393│     11│   81.00│    30│        92│
-│had too much to drink to drive safely will   certain    │       │       │          │       │        │      │          │
-│A. Get stopped by the police?                Very likely│    384│    552│       936│     14│  171.00│    65│       185│
-│                                             Somewhat   │    590│   1249│      1839│     20│  265.00│    92│       285│
-│                                             likely     │       │       │          │       │        │      │          │
-│                                             Somewhat   │    278│    647│       925│      6│  116.00│    38│       122│
-│                                             unlikely   │       │       │          │       │        │      │          │
-│                                             Very       │    141│    290│       431│      4│   59.00│    22│        63│
-│                                             unlikely   │       │       │          │       │        │      │          │
-╰────────────────────────────────────────────────────────┴───────┴───────┴──────────┴───────┴────────┴──────┴──────────╯
+                                              Custom Tables
+╭──────────────────┬───────────────────────────────────────────────────────────────────────────────────╮
+│                  │                                       Gender                                      │
+│                  ├─────────────────────────────────────────┬─────────────────────────────────────────┤
+│                  │                   Male                  │                  Female                 │
+│                  ├─────────────────────────────────────────┼─────────────────────────────────────────┤
+│                  │         Favorite day of the week        │         Favorite day of the week        │
+│                  ├───┬───┬───┬───┬───┬───┬───┬───────┬─────┼───┬───┬───┬───┬───┬───┬───┬───────┬─────┤
+│                  │SUN│MON│TUE│WED│THU│FRI│SAT│Weekend│Total│SUN│MON│TUE│WED│THU│FRI│SAT│Weekend│Total│
+├──────────────────┼───┼───┼───┼───┼───┼───┼───┼───────┼─────┼───┼───┼───┼───┼───┼───┼───┼───────┼─────┤
+│Favorite month JAN│ 10│  3│  8│  6│  4│  2│  7│     17│   40│  9│  6│  4│  2│  7│  5│  3│     12│   36│
+│               FEB│  6│  8│  6│  4│  2│  7│  5│     11│   38│ 12│  4│  2│  7│  5│  3│  8│     20│   41│
+│               MAR│ 16│  6│  4│  2│  7│  5│  3│     19│   43│  8│  2│  7│  5│  3│  8│  6│     14│   39│
+│               Q1 │ 32│ 17│ 18│ 12│ 13│ 14│ 15│       │     │ 29│ 12│ 13│ 14│ 15│ 16│ 17│       │     │
+│               APR│ 12│  4│  2│  7│  5│  3│  8│     20│   41│  4│  7│  5│  3│  8│  6│  4│      8│   37│
+│               MAY│  8│  2│  7│  5│  3│  8│  6│     14│   39│ 14│  5│  3│  8│  6│  4│  2│     16│   42│
+│               JUN│  4│  7│  5│  3│  8│  6│  4│      8│   37│ 10│  3│  8│  6│  4│  2│  7│     17│   40│
+│               Q2 │ 24│ 13│ 14│ 15│ 16│ 17│ 18│      .│     │ 28│ 15│ 16│ 17│ 18│ 12│ 13│      .│     │
+│               JUL│ 14│  5│  3│  8│  6│  4│  2│     16│   42│  6│  8│  6│  4│  2│  7│  5│     11│   38│
+│               AUG│ 10│  3│  8│  6│  4│  2│  7│     17│   40│ 16│  6│  4│  2│  7│  5│  3│     19│   43│
+│               SEP│  6│  8│  6│  4│  2│  7│  5│     11│   38│ 12│  4│  2│  7│  5│  3│  8│     20│   41│
+│               Q3 │ 54│ 29│ 31│ 33│ 28│ 30│ 32│       │     │ 62│ 33│ 28│ 30│ 32│ 27│ 29│       │     │
+│               OCT│ 16│  6│  4│  2│  7│  5│  3│     19│   43│  8│  2│  7│  5│  3│  8│  6│     14│   39│
+│               NOV│ 12│  4│  2│  7│  5│  3│  8│     20│   41│  4│  7│  5│  3│  8│  6│  4│      8│   37│
+│               DEC│  8│  2│  7│  5│  3│  8│  6│     14│   39│ 14│  5│  3│  8│  6│  4│  2│     16│   42│
+│               Q4 │ 36│ 12│ 13│ 14│ 15│ 16│ 17│       │     │ 26│ 14│ 15│ 16│ 17│ 18│ 12│       │     │
+╰──────────────────┴───┴───┴───┴───┴───┴───┴───┴───────┴─────┴───┴───┴───┴───┴───┴───┴───┴───────┴─────╯
 ])
 AT_CLEANUP
 
@@ -1654,7 +1872,6 @@ CTABLES /TABLE AgeGroup BY qns3a /CLABELS COLLABELS=OPPOSITE.
 CTABLES /TABLE AgeGroup BY qns3a /CLABELS ROWLABELS=LAYER.
 CTABLES /TABLE AgeGroup BY qns3a /CLABELS COLLABELS=LAYER.
 ]])
-pwd
 AT_CHECK([pspp ctables.sps --table-look="$builddir"/all-layers.stt -O box=unicode -O width=120], [0], [dnl
              Custom Tables
 ╭───────────────────────┬────────────╮
@@ -2809,11 +3026,11 @@ AT_DATA([ctables.sps],
 [[GET 'nhtsa.sav'.
 CTABLES
     /VLABELS VARIABLES=ALL DISPLAY=NAME
-    /TABLE qn61 > qn57 BY qnd7a > qn86 + qn64b BY qns3a[TABLE.ID, LAYER.ID, SUBTABLE.ID]
+    /TABLE qn61 > qn57 BY qnd7a > qn86 + qn64b BY qns3a[TABLEID, LAYERID, SUBTABLEID]
     /SLABELS POSITION=ROW
-    /TABLE qn61 > qn57 BY qnd7a > qn86 + qn64b BY qns3a[ROW.ID, LAYERROW.ID]
+    /TABLE qn61 > qn57 BY qnd7a > qn86 + qn64b BY qns3a[ROWID, LAYERROWID]
     /SLABELS POSITION=ROW
-    /TABLE qn61 > qn57 BY qnd7a > qn86 + qn64b BY qns3a[COL.ID, LAYERCOL.ID]
+    /TABLE qn61 > qn57 BY qnd7a > qn86 + qn64b BY qns3a[COLID, LAYERCOLID]
     /SLABELS POSITION=ROW.
 ]])
 AT_CHECK([pspp ctables.sps --table-look="$builddir"/all-layers.stt -O box=unicode -O width=80], [0], [dnl
@@ -2971,6 +3188,213 @@ Female
 ])
 AT_CLEANUP
 
+AT_SETUP([CTABLES area definitions with CLABELS OPPOSITE])
+AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
+AT_DATA([ctables.sps],
+[[GET 'nhtsa.sav'.
+CTABLES
+    /VLABELS VARIABLES=ALL DISPLAY=NAME
+    /TABLE qn26 > qn61 > qn57 BY qn27 > qnd7a > qn86 BY qns3a[TABLEID, LAYERID, SUBTABLEID]
+    /SLABELS POSITION=ROW
+    /CLABELS ROWLABELS=OPPOSITE
+    /TABLE qn26 > qn61 > qn57 BY qn27 > qnd7a > qn86 BY qns3a[ROWID, LAYERROWID]
+    /SLABELS POSITION=ROW
+    /CLABELS ROWLABELS=OPPOSITE
+    /TABLE qn26 > qn61 > qn57 BY qn27 > qnd7a > qn86 BY qns3a[COLID, LAYERCOLID]
+    /SLABELS POSITION=ROW
+    /CLABELS ROWLABELS=OPPOSITE.
+]])
+AT_CHECK([pspp ctables.sps --table-look="$builddir"/all-layers.stt -O box=unicode -O width=120], [0], [dnl
+                                        Custom Tables
+Male
+╭──────────────────────────────────┬───────────────────────────────────────────────────────╮
+│                                  │                          QN27                         │
+│                                  ├───────────────────────────┬───────────────────────────┤
+│                                  │            Yes            │             No            │
+│                                  ├───────────────────────────┼───────────────────────────┤
+│                                  │           QND7A           │           QND7A           │
+│                                  ├─────────────┬─────────────┼─────────────┬─────────────┤
+│                                  │     Yes     │      No     │     Yes     │      No     │
+│                                  ├─────────────┼─────────────┼─────────────┼─────────────┤
+│                                  │     QN86    │     QN86    │     QN86    │     QN86    │
+│                                  ├──────┬──────┼──────┬──────┼──────┬──────┼──────┬──────┤
+│                                  │  Yes │  No  │  Yes │  No  │  Yes │  No  │  Yes │  No  │
+│                                  ├───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┤
+│                                  │Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│
+├──────────────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│QN26 Yes QN61 Yes QN57 Table ID   │  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│
+│                       Layer ID   │  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│
+│                       Subtable ID│  1│ 1│  2│ 2│  3│ 3│  4│ 4│  5│ 5│  6│ 6│  7│ 7│  8│ 8│
+│             ╶────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│              No  QN57 Table ID   │  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│
+│                       Layer ID   │  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│
+│                       Subtable ID│  1│ 1│  2│ 2│  3│ 3│  4│ 4│  5│ 5│  6│ 6│  7│ 7│  8│ 8│
+│    ╶─────────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│     No  QN61 Yes QN57 Table ID   │  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│
+│                       Layer ID   │  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│
+│                       Subtable ID│  9│ 9│ 10│10│ 11│11│ 12│12│ 13│13│ 14│14│ 15│15│ 16│16│
+│             ╶────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│              No  QN57 Table ID   │  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│
+│                       Layer ID   │  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│
+│                       Subtable ID│  9│ 9│ 10│10│ 11│11│ 12│12│ 13│13│ 14│14│ 15│15│ 16│16│
+╰──────────────────────────────────┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──╯
+
+                                        Custom Tables
+Female
+╭──────────────────────────────────┬───────────────────────────────────────────────────────╮
+│                                  │                          QN27                         │
+│                                  ├───────────────────────────┬───────────────────────────┤
+│                                  │            Yes            │             No            │
+│                                  ├───────────────────────────┼───────────────────────────┤
+│                                  │           QND7A           │           QND7A           │
+│                                  ├─────────────┬─────────────┼─────────────┬─────────────┤
+│                                  │     Yes     │      No     │     Yes     │      No     │
+│                                  ├─────────────┼─────────────┼─────────────┼─────────────┤
+│                                  │     QN86    │     QN86    │     QN86    │     QN86    │
+│                                  ├──────┬──────┼──────┬──────┼──────┬──────┼──────┬──────┤
+│                                  │  Yes │  No  │  Yes │  No  │  Yes │  No  │  Yes │  No  │
+│                                  ├───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┤
+│                                  │Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│
+├──────────────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│QN26 Yes QN61 Yes QN57 Table ID   │  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│
+│                       Layer ID   │  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│
+│                       Subtable ID│ 17│17│ 18│18│ 19│19│ 20│20│ 21│21│ 22│22│ 23│23│ 24│24│
+│             ╶────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│              No  QN57 Table ID   │  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│
+│                       Layer ID   │  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│
+│                       Subtable ID│ 17│17│ 18│18│ 19│19│ 20│20│ 21│21│ 22│22│ 23│23│ 24│24│
+│    ╶─────────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│     No  QN61 Yes QN57 Table ID   │  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│
+│                       Layer ID   │  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│
+│                       Subtable ID│ 25│25│ 26│26│ 27│27│ 28│28│ 29│29│ 30│30│ 31│31│ 32│32│
+│             ╶────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│              No  QN57 Table ID   │  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│
+│                       Layer ID   │  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│
+│                       Subtable ID│ 25│25│ 26│26│ 27│27│ 28│28│ 29│29│ 30│30│ 31│31│ 32│32│
+╰──────────────────────────────────┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──╯
+
+                                        Custom Tables
+Male
+╭───────────────────────────────────┬───────────────────────────────────────────────────────╮
+│                                   │                          QN27                         │
+│                                   ├───────────────────────────┬───────────────────────────┤
+│                                   │            Yes            │             No            │
+│                                   ├───────────────────────────┼───────────────────────────┤
+│                                   │           QND7A           │           QND7A           │
+│                                   ├─────────────┬─────────────┼─────────────┬─────────────┤
+│                                   │     Yes     │      No     │     Yes     │      No     │
+│                                   ├─────────────┼─────────────┼─────────────┼─────────────┤
+│                                   │     QN86    │     QN86    │     QN86    │     QN86    │
+│                                   ├──────┬──────┼──────┬──────┼──────┬──────┼──────┬──────┤
+│                                   │  Yes │  No  │  Yes │  No  │  Yes │  No  │  Yes │  No  │
+│                                   ├───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┤
+│                                   │Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│
+├───────────────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│QN26 Yes QN61 Yes QN57 Row ID      │  1│ 1│  2│ 2│  3│ 3│  4│ 4│  5│ 5│  6│ 6│  7│ 7│  8│ 8│
+│                       Layer Row ID│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│  1│ 1│
+│             ╶─────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│              No  QN57 Row ID      │  9│ 9│ 10│10│ 11│11│ 12│12│ 13│13│ 14│14│ 15│15│ 16│16│
+│                       Layer Row ID│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│  2│ 2│
+│    ╶──────────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│     No  QN61 Yes QN57 Row ID      │ 17│17│ 18│18│ 19│19│ 20│20│ 21│21│ 22│22│ 23│23│ 24│24│
+│                       Layer Row ID│  3│ 3│  3│ 3│  3│ 3│  3│ 3│  3│ 3│  3│ 3│  3│ 3│  3│ 3│
+│             ╶─────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│              No  QN57 Row ID      │ 25│25│ 26│26│ 27│27│ 28│28│ 29│29│ 30│30│ 31│31│ 32│32│
+│                       Layer Row ID│  4│ 4│  4│ 4│  4│ 4│  4│ 4│  4│ 4│  4│ 4│  4│ 4│  4│ 4│
+╰───────────────────────────────────┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──╯
+
+                                        Custom Tables
+Female
+╭───────────────────────────────────┬───────────────────────────────────────────────────────╮
+│                                   │                          QN27                         │
+│                                   ├───────────────────────────┬───────────────────────────┤
+│                                   │            Yes            │             No            │
+│                                   ├───────────────────────────┼───────────────────────────┤
+│                                   │           QND7A           │           QND7A           │
+│                                   ├─────────────┬─────────────┼─────────────┬─────────────┤
+│                                   │     Yes     │      No     │     Yes     │      No     │
+│                                   ├─────────────┼─────────────┼─────────────┼─────────────┤
+│                                   │     QN86    │     QN86    │     QN86    │     QN86    │
+│                                   ├──────┬──────┼──────┬──────┼──────┬──────┼──────┬──────┤
+│                                   │  Yes │  No  │  Yes │  No  │  Yes │  No  │  Yes │  No  │
+│                                   ├───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┤
+│                                   │Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│
+├───────────────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│QN26 Yes QN61 Yes QN57 Row ID      │ 33│33│ 34│34│ 35│35│ 36│36│ 37│37│ 38│38│ 39│39│ 40│40│
+│                       Layer Row ID│  5│ 5│  5│ 5│  5│ 5│  5│ 5│  5│ 5│  5│ 5│  5│ 5│  5│ 5│
+│             ╶─────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│              No  QN57 Row ID      │ 41│41│ 42│42│ 43│43│ 44│44│ 45│45│ 46│46│ 47│47│ 48│48│
+│                       Layer Row ID│  6│ 6│  6│ 6│  6│ 6│  6│ 6│  6│ 6│  6│ 6│  6│ 6│  6│ 6│
+│    ╶──────────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│     No  QN61 Yes QN57 Row ID      │ 49│49│ 50│50│ 51│51│ 52│52│ 53│53│ 54│54│ 55│55│ 56│56│
+│                       Layer Row ID│  7│ 7│  7│ 7│  7│ 7│  7│ 7│  7│ 7│  7│ 7│  7│ 7│  7│ 7│
+│             ╶─────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│              No  QN57 Row ID      │ 57│57│ 58│58│ 59│59│ 60│60│ 61│61│ 62│62│ 63│63│ 64│64│
+│                       Layer Row ID│  8│ 8│  8│ 8│  8│ 8│  8│ 8│  8│ 8│  8│ 8│  8│ 8│  8│ 8│
+╰───────────────────────────────────┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──╯
+
+                                          Custom Tables
+Male
+╭──────────────────────────────────────┬───────────────────────────────────────────────────────╮
+│                                      │                          QN27                         │
+│                                      ├───────────────────────────┬───────────────────────────┤
+│                                      │            Yes            │             No            │
+│                                      ├───────────────────────────┼───────────────────────────┤
+│                                      │           QND7A           │           QND7A           │
+│                                      ├─────────────┬─────────────┼─────────────┬─────────────┤
+│                                      │     Yes     │      No     │     Yes     │      No     │
+│                                      ├─────────────┼─────────────┼─────────────┼─────────────┤
+│                                      │     QN86    │     QN86    │     QN86    │     QN86    │
+│                                      ├──────┬──────┼──────┬──────┼──────┬──────┼──────┬──────┤
+│                                      │  Yes │  No  │  Yes │  No  │  Yes │  No  │  Yes │  No  │
+│                                      ├───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┤
+│                                      │Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│
+├──────────────────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│QN26 Yes QN61 Yes QN57 Column ID      │  1│ 2│  4│ 3│  6│ 5│  8│ 7│  9│10│ 11│12│ 14│13│ 15│16│
+│                       Layer Column ID│  1│ 2│  4│ 3│  6│ 5│  8│ 7│  9│10│ 11│12│ 14│13│ 15│16│
+│             ╶────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│              No  QN57 Column ID      │  1│ 2│  4│ 3│  6│ 5│  8│ 7│  9│10│ 11│12│ 14│13│ 15│16│
+│                       Layer Column ID│  1│ 2│  4│ 3│  6│ 5│  8│ 7│  9│10│ 11│12│ 14│13│ 15│16│
+│    ╶─────────────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│     No  QN61 Yes QN57 Column ID      │ 18│17│ 19│20│ 22│21│ 23│24│ 25│26│ 27│28│ 29│30│ 32│31│
+│                       Layer Column ID│  1│ 2│  4│ 3│  6│ 5│  8│ 7│  9│10│ 11│12│ 14│13│ 15│16│
+│             ╶────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│              No  QN57 Column ID      │ 18│17│ 19│20│ 22│21│ 23│24│ 25│26│ 27│28│ 29│30│ 32│31│
+│                       Layer Column ID│  1│ 2│  4│ 3│  6│ 5│  8│ 7│  9│10│ 11│12│ 14│13│ 15│16│
+╰──────────────────────────────────────┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──╯
+
+                                          Custom Tables
+Female
+╭──────────────────────────────────────┬───────────────────────────────────────────────────────╮
+│                                      │                          QN27                         │
+│                                      ├───────────────────────────┬───────────────────────────┤
+│                                      │            Yes            │             No            │
+│                                      ├───────────────────────────┼───────────────────────────┤
+│                                      │           QND7A           │           QND7A           │
+│                                      ├─────────────┬─────────────┼─────────────┬─────────────┤
+│                                      │     Yes     │      No     │     Yes     │      No     │
+│                                      ├─────────────┼─────────────┼─────────────┼─────────────┤
+│                                      │     QN86    │     QN86    │     QN86    │     QN86    │
+│                                      ├──────┬──────┼──────┬──────┼──────┬──────┼──────┬──────┤
+│                                      │  Yes │  No  │  Yes │  No  │  Yes │  No  │  Yes │  No  │
+│                                      ├───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┼───┬──┤
+│                                      │Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│Yes│No│
+├──────────────────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│QN26 Yes QN61 Yes QN57 Column ID      │ 33│34│ 36│35│ 37│38│ 39│40│ 42│41│ 44│43│ 45│46│ 47│48│
+│                       Layer Column ID│ 17│18│ 20│19│ 21│22│ 23│24│ 26│25│ 28│27│ 29│30│ 31│32│
+│             ╶────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│              No  QN57 Column ID      │ 33│34│ 36│35│ 37│38│ 39│40│ 42│41│ 44│43│ 45│46│ 47│48│
+│                       Layer Column ID│ 17│18│ 20│19│ 21│22│ 23│24│ 26│25│ 28│27│ 29│30│ 31│32│
+│    ╶─────────────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│     No  QN61 Yes QN57 Column ID      │ 49│50│ 51│52│ 54│53│ 56│55│ 57│58│ 60│59│ 62│61│ 64│63│
+│                       Layer Column ID│ 17│18│ 20│19│ 21│22│ 23│24│ 26│25│ 28│27│ 29│30│ 31│32│
+│             ╶────────────────────────┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┼───┼──┤
+│              No  QN57 Column ID      │ 49│50│ 51│52│ 54│53│ 56│55│ 57│58│ 60│59│ 62│61│ 64│63│
+│                       Layer Column ID│ 17│18│ 20│19│ 21│22│ 23│24│ 26│25│ 28│27│ 29│30│ 31│32│
+╰──────────────────────────────────────┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──┴───┴──╯
+])
+AT_CLEANUP
+
 AT_SETUP([CTABLES categorical summary functions])
 AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
 AT_DATA([ctables.sps],
@@ -3036,7 +3460,6 @@ AT_CHECK([pspp ctables.sps -O box=unicode -O width=120], [0], [dnl
 ])
 AT_CLEANUP
 
-
 AT_SETUP([CTABLES scale summary functions])
 AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
 AT_DATA([ctables.sps],
@@ -3316,3 +3739,273 @@ AT_CHECK([pspp ctables.sps -O box=unicode], [0], [dnl
 ])
 AT_CLEANUP
 
+AT_SETUP([CTABLES with SPLIT FILE])
+AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
+AT_DATA([ctables.sps],
+[[GET 'nhtsa.sav'.
+
+SORT CASES BY qns3a.
+
+CTABLES /TABLE qn105ba.
+
+* Layered split has no effect on output.
+SPLIT FILE BY qns3a.
+CTABLES /TABLE qn105ba.
+
+* Add column variable qns3a to compare against separate splits.
+CTABLES /TABLE qn105ba BY qns3a.
+
+* Separate splits are truly output separately.
+SPLIT FILE SEPARATE BY qns3a.
+CTABLES /TABLE qn105ba.
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl
+                                  Custom Tables
+╭────────────────────────────────────────────────────────────────────────┬─────╮
+│                                                                        │Count│
+├────────────────────────────────────────────────────────────────────────┼─────┤
+│105b. How likely is it that drivers who have had too much   Almost      │  700│
+│to drink to drive safely will A. Get stopped by the police? certain     │     │
+│                                                            Very likely │ 1502│
+│                                                            Somewhat    │ 2763│
+│                                                            likely      │     │
+│                                                            Somewhat    │ 1307│
+│                                                            unlikely    │     │
+│                                                            Very        │  609│
+│                                                            unlikely    │     │
+╰────────────────────────────────────────────────────────────────────────┴─────╯
+
+                                  Custom Tables
+╭────────────────────────────────────────────────────────────────────────┬─────╮
+│                                                                        │Count│
+├────────────────────────────────────────────────────────────────────────┼─────┤
+│105b. How likely is it that drivers who have had too much   Almost      │  700│
+│to drink to drive safely will A. Get stopped by the police? certain     │     │
+│                                                            Very likely │ 1502│
+│                                                            Somewhat    │ 2763│
+│                                                            likely      │     │
+│                                                            Somewhat    │ 1307│
+│                                                            unlikely    │     │
+│                                                            Very        │  609│
+│                                                            unlikely    │     │
+╰────────────────────────────────────────────────────────────────────────┴─────╯
+
+                                  Custom Tables
+╭─────────────────────────────────────────────────────────────────┬────────────╮
+│                                                                 │S3a. GENDER:│
+│                                                                 ├─────┬──────┤
+│                                                                 │ Male│Female│
+│                                                                 ├─────┼──────┤
+│                                                                 │Count│ Count│
+├─────────────────────────────────────────────────────────────────┼─────┼──────┤
+│105b. How likely is it that drivers who have had too Almost      │  297│   403│
+│much to drink to drive safely will A. Get stopped by certain     │     │      │
+│the police?                                          Very likely │  660│   842│
+│                                                     Somewhat    │ 1174│  1589│
+│                                                     likely      │     │      │
+│                                                     Somewhat    │  640│   667│
+│                                                     unlikely    │     │      │
+│                                                     Very        │  311│   298│
+│                                                     unlikely    │     │      │
+╰─────────────────────────────────────────────────────────────────┴─────┴──────╯
+
+    Split Values
+╭────────────┬─────╮
+│Variable    │Value│
+├────────────┼─────┤
+│S3a. GENDER:│Male │
+╰────────────┴─────╯
+
+                                  Custom Tables
+╭────────────────────────────────────────────────────────────────────────┬─────╮
+│                                                                        │Count│
+├────────────────────────────────────────────────────────────────────────┼─────┤
+│105b. How likely is it that drivers who have had too much   Almost      │  297│
+│to drink to drive safely will A. Get stopped by the police? certain     │     │
+│                                                            Very likely │  660│
+│                                                            Somewhat    │ 1174│
+│                                                            likely      │     │
+│                                                            Somewhat    │  640│
+│                                                            unlikely    │     │
+│                                                            Very        │  311│
+│                                                            unlikely    │     │
+╰────────────────────────────────────────────────────────────────────────┴─────╯
+
+     Split Values
+╭────────────┬──────╮
+│Variable    │ Value│
+├────────────┼──────┤
+│S3a. GENDER:│Female│
+╰────────────┴──────╯
+
+                                  Custom Tables
+╭────────────────────────────────────────────────────────────────────────┬─────╮
+│                                                                        │Count│
+├────────────────────────────────────────────────────────────────────────┼─────┤
+│105b. How likely is it that drivers who have had too much   Almost      │  403│
+│to drink to drive safely will A. Get stopped by the police? certain     │     │
+│                                                            Very likely │  842│
+│                                                            Somewhat    │ 1589│
+│                                                            likely      │     │
+│                                                            Somewhat    │  667│
+│                                                            unlikely    │     │
+│                                                            Very        │  298│
+│                                                            unlikely    │     │
+╰────────────────────────────────────────────────────────────────────────┴─────╯
+])
+AT_CLEANUP
+
+AT_SETUP([CTABLES variable level inference])
+AT_DATA([data.txt], [dnl
+dnl n1 has 10 unique small values -> nominal.
+dnl n2 has 23 unique small values -> nominal.
+dnl n3 is all missing -> nominal.
+dnl s1 has 24 unique small values -> scale.
+dnl s2 has one negative value -> scale.
+dnl s3 has one non-integer value -> scale.
+dnl s4 has no valid values less than 10 -> scale.
+dnl s5 has no valid values less than 10,000 -> scale.
+1  1  . 1  1  1    10 10001
+2  2  . 2  2  2    11 10002
+3  3  . 3  3  3    12 10003
+4  4  . 4  4  4    13 10004
+5  5  . 5  5  5    14 10005
+6  6  . 6  6  6    15 10006
+7  7  . 7  7  7    16 10007
+8  8  . 8  8  8    17 10008
+9  9  . 9  9  9    18 10009
+10 10 . 10 10 10.5 19 110000
+1  11 . 11 -1 1    11 10001
+2  12 . 12 2  2    12 10002
+3  13 . 13 3  3    13 10003
+4  14 . 14 4  4    14 10004
+5  15 . 15 5  5    15 10005
+6  16 . 16 6  6    16 10006
+7  17 . 17 7  7    17 10007
+8  18 . 18 8  8    18 10008
+9  19 . 19 9  9    19 10009
+1  20 . 20 1  1    20 10001
+2  21 . 21 2  2    21 10002
+3  22 . 22 3  3    22 10003
+4  23 . 23 4  4    23 10004
+5  23 . 24 5  5    24 10005
+6  23 . 24 6  6    25 10006
+])
+
+AT_DATA([ctables.sps], [dnl
+DATA LIST LIST file='data.txt' NOTABLE /n1 to n3 s1 to s5.
+
+* Nominal formats (copied from data that will default to scale).
+COMPUTE n4=s1.
+COMPUTE n5=s1.
+FORMATS n4(WKDAY5) n5(MONTH5).
+
+* Scale formats (copied from data that will default to nominal).
+COMPUTE s6=n1.
+COMPUTE s7=n1.
+COMPUTE s8=n1.
+FORMATS s6(DOLLAR6.2) s7(CCA8.2) s8(DATETIME17).
+
+STRING string(A8).
+
+DISPLAY DICTIONARY.
+CTABLES /TABLE n1 + n2 + n3 + string + s1 + s2 + s3 + s4 + s5.
+DISPLAY DICTIONARY.
+])
+
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl
+                                    Variables
+╭──────┬────────┬──────────────┬─────┬─────┬─────────┬────────────┬────────────╮
+│      │        │  Measurement │     │     │         │            │            │
+│Name  │Position│     Level    │ Role│Width│Alignment│Print Format│Write Format│
+├──────┼────────┼──────────────┼─────┼─────┼─────────┼────────────┼────────────┤
+│n1    │       1│Unknown       │Input│    8│Right    │F8.2        │F8.2        │
+│n2    │       2│Unknown       │Input│    8│Right    │F8.2        │F8.2        │
+│n3    │       3│Unknown       │Input│    8│Right    │F8.2        │F8.2        │
+│s1    │       4│Unknown       │Input│    8│Right    │F8.2        │F8.2        │
+│s2    │       5│Unknown       │Input│    8│Right    │F8.2        │F8.2        │
+│s3    │       6│Unknown       │Input│    8│Right    │F8.2        │F8.2        │
+│s4    │       7│Unknown       │Input│    8│Right    │F8.2        │F8.2        │
+│s5    │       8│Unknown       │Input│    8│Right    │F8.2        │F8.2        │
+│n4    │       9│Unknown       │Input│    8│Right    │WKDAY5      │WKDAY5      │
+│n5    │      10│Unknown       │Input│    8│Right    │MONTH5      │MONTH5      │
+│s6    │      11│Unknown       │Input│    8│Right    │DOLLAR6.2   │DOLLAR6.2   │
+│s7    │      12│Unknown       │Input│    8│Right    │CCA8.2      │CCA8.2      │
+│s8    │      13│Unknown       │Input│    8│Right    │DATETIME17.0│DATETIME17.0│
+│string│      14│Nominal       │Input│    8│Left     │A8          │A8          │
+╰──────┴────────┴──────────────┴─────┴─────┴─────────┴────────────┴────────────╯
+
+        Custom Tables
+╭────────────┬─────┬────────╮
+│            │Count│  Mean  │
+├────────────┼─────┼────────┤
+│n1     1.00 │    3│        │
+│       2.00 │    3│        │
+│       3.00 │    3│        │
+│       4.00 │    3│        │
+│       5.00 │    3│        │
+│       6.00 │    3│        │
+│       7.00 │    2│        │
+│       8.00 │    2│        │
+│       9.00 │    2│        │
+│       10.00│    1│        │
+├────────────┼─────┼────────┤
+│n2     1.00 │    1│        │
+│       2.00 │    1│        │
+│       3.00 │    1│        │
+│       4.00 │    1│        │
+│       5.00 │    1│        │
+│       6.00 │    1│        │
+│       7.00 │    1│        │
+│       8.00 │    1│        │
+│       9.00 │    1│        │
+│       10.00│    1│        │
+│       11.00│    1│        │
+│       12.00│    1│        │
+│       13.00│    1│        │
+│       14.00│    1│        │
+│       15.00│    1│        │
+│       16.00│    1│        │
+│       17.00│    1│        │
+│       18.00│    1│        │
+│       19.00│    1│        │
+│       20.00│    1│        │
+│       21.00│    1│        │
+│       22.00│    1│        │
+│       23.00│    3│        │
+├────────────┼─────┼────────┤
+│string      │   25│        │
+├────────────┼─────┼────────┤
+│s1          │     │   12.96│
+├────────────┼─────┼────────┤
+│s2          │     │    4.76│
+├────────────┼─────┼────────┤
+│s3          │     │    4.86│
+├────────────┼─────┼────────┤
+│s4          │     │   16.60│
+├────────────┼─────┼────────┤
+│s5          │     │14004.44│
+╰────────────┴─────┴────────╯
+
+                                    Variables
+╭──────┬────────┬──────────────┬─────┬─────┬─────────┬────────────┬────────────╮
+│      │        │  Measurement │     │     │         │            │            │
+│Name  │Position│     Level    │ Role│Width│Alignment│Print Format│Write Format│
+├──────┼────────┼──────────────┼─────┼─────┼─────────┼────────────┼────────────┤
+│n1    │       1│Nominal       │Input│    8│Right    │F8.2        │F8.2        │
+│n2    │       2│Nominal       │Input│    8│Right    │F8.2        │F8.2        │
+│n3    │       3│Nominal       │Input│    8│Right    │F8.2        │F8.2        │
+│s1    │       4│Scale         │Input│    8│Right    │F8.2        │F8.2        │
+│s2    │       5│Scale         │Input│    8│Right    │F8.2        │F8.2        │
+│s3    │       6│Scale         │Input│    8│Right    │F8.2        │F8.2        │
+│s4    │       7│Scale         │Input│    8│Right    │F8.2        │F8.2        │
+│s5    │       8│Scale         │Input│    8│Right    │F8.2        │F8.2        │
+│n4    │       9│Nominal       │Input│    8│Right    │WKDAY5      │WKDAY5      │
+│n5    │      10│Nominal       │Input│    8│Right    │MONTH5      │MONTH5      │
+│s6    │      11│Scale         │Input│    8│Right    │DOLLAR6.2   │DOLLAR6.2   │
+│s7    │      12│Scale         │Input│    8│Right    │CCA8.2      │CCA8.2      │
+│s8    │      13│Scale         │Input│    8│Right    │DATETIME17.0│DATETIME17.0│
+│string│      14│Nominal       │Input│    8│Left     │A8          │A8          │
+╰──────┴────────┴──────────────┴─────┴─────┴─────────┴────────────┴────────────╯
+])
+AT_CLEANUP