CTABLES strings work
[pspp] / tests / language / stats / ctables.at
index 82e0f9bea8bfc703cc6cdc99331461437a8a12a7..ebda3ce826c8378a8ff221130c282688024304da 100644 (file)
@@ -2,12 +2,10 @@ AT_BANNER([CTABLES])
 
 dnl Features not yet tested:
 dnl - Preprocessing to distinguish categorical from scale.
-dnl - String variables and values
 dnl - Testing details of missing value handling in summaries.
 dnl - test CLABELS ROWLABELS=LAYER.
 dnl - Test VLABELS.
 dnl - Test WEIGHT and adjustment weights.
-dnl - EMPTY=INCLUDE For string ranges.
 dnl - Summary functions:
 dnl   * Separate summary functions for totals and subtotals.
 dnl   * )CILEVEL in summary label specification
@@ -16,10 +14,8 @@ dnl   * VALUE
 dnl   * LABEL
 dnl   * ascending/descending
 dnl - CATEGORIES:
-dnl   * String values
 dnl   * Date values
 dnl   * THRU (numeric ranges)
-dnl   * THRU (string ranges)
 dnl   * OTHERNM
 dnl - FORMAT:
 dnl   * MINCOLWIDTH, MAXCOLWIDTH, UNITS.
@@ -54,23 +50,6 @@ dnl   * .LCL and .UCL suffixes.
 dnl   * .SE suffixes.
 dnl - CATEGORIES:
 dnl   * Data-dependent sorting.
-dnl
-dnl
-dnl Bug:
-dnl     CTABLES /TABLE=qnd1 [MEAN, MEDIAN] BY qns3a.
-dnl produces a bad median:
-dnl                     Custom Tables
-dnl +--------------------------+-----------------------+
-dnl |                          |      S3a. GENDER:     |
-dnl |                          +-----------+-----------+
-dnl |                          |    Male   |   Female  |
-dnl |                          +----+------+----+------+
-dnl |                          |Mean|Median|Mean|Median|
-dnl +--------------------------+----+------+----+------+
-dnl |D1. AGE: What is your age?|  46|   999|  50|   999|
-dnl +--------------------------+----+------+----+------+
-
-
 
 AT_SETUP([CTABLES parsing])
 AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
@@ -760,6 +739,88 @@ Every day
 ])
 AT_CLEANUP
 
+AT_SETUP([CTABLES one string variable])
+AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
+AT_DATA([ctables.sps],
+[[GET 'nhtsa.sav'.
+STRING licensed(A8).
+MISSING VALUES licensed('DontKnow', 'Refused').
+RECODE qnd7a(1='Yes')(2='No')(3='DontKnow')(4='Refused') INTO licensed.
+CTABLES /TABLE licensed.
+CTABLES /TABLE licensed [COUNT, TOTALS[COUNT, VALIDN]] /CATEGORIES VARIABLES=ALL TOTAL=YES MISSING=INCLUDE.
+CTABLES /TABLE licensed /CATEGORIES VARIABLES=licensed ['Yes', 'No'] TOTAL=YES.
+* Notice that the string matching is case-sensitive.
+CTABLES /TABLE licensed /CATEGORIES VARIABLES=licensed ['Yes', 'no'] TOTAL=YES.
+CTABLES /TABLE licensed /CATEGORIES VARIABLES=licensed ['No' THRU 'yes'] TOTAL=YES.
+CTABLES
+    /PCOMPUTE &notyes=EXPR(['No']+['DontKnow']+['Refused'])
+    /PPROPERTIES &notyes LABEL='Not Yes' HIDESOURCECATS=YES
+    /TABLE licensed
+    /CATEGORIES VARIABLES=licensed ['Yes', &notyes, 'No', 'DontKnow', 'Refused'].
+CTABLES
+    /PCOMPUTE &notyes=EXPR(['No']+['DontKnow']+['Refused'])
+    /PPROPERTIES &notyes LABEL='Not Yes' HIDESOURCECATS=YES
+    /TABLE licensed
+    /CATEGORIES VARIABLES=licensed ['Yes', &notyes, 'DontKnow' THRU 'No', 'Refused'].
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl
+    Custom Tables
+╭────────────┬─────╮
+│            │Count│
+├────────────┼─────┤
+│licensed No │  572│
+│         Yes│ 6379│
+╰────────────┴─────╯
+
+          Custom Tables
+╭─────────────────┬─────┬───────╮
+│                 │Count│Valid N│
+├─────────────────┼─────┼───────┤
+│licensed DontKnow│    4│       │
+│         No      │  572│       │
+│         Refused │   44│       │
+│         Yes     │ 6379│       │
+│         Total   │ 6999│   6951│
+╰─────────────────┴─────┴───────╯
+
+     Custom Tables
+╭──────────────┬─────╮
+│              │Count│
+├──────────────┼─────┤
+│licensed Yes  │ 6379│
+│         No   │  572│
+│         Total│ 6951│
+╰──────────────┴─────╯
+
+     Custom Tables
+╭──────────────┬─────╮
+│              │Count│
+├──────────────┼─────┤
+│licensed Yes  │ 6379│
+│         no   │    0│
+│         Total│ 6379│
+╰──────────────┴─────╯
+
+      Custom Tables
+╭────────────────┬─────╮
+│                │Count│
+├────────────────┼─────┤
+│licensed No     │  572│
+│         Refused│   44│
+│         Yes    │ 6379│
+│         Total  │ 6995│
+╰────────────────┴─────╯
+
+      Custom Tables
+╭────────────────┬─────╮
+│                │Count│
+├────────────────┼─────┤
+│licensed Yes    │ 6379│
+│         Not Yes│  620│
+╰────────────────┴─────╯
+])
+AT_CLEANUP
+
 AT_SETUP([CTABLES one scale variable])
 AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
 AT_DATA([ctables.sps],