}
case CTPO_CAT_NUMBER:
- case CTPO_CAT_STRING:
case CTPO_CAT_MISSING:
case CTPO_CAT_OTHERNM:
case CTPO_CAT_SUBTOTAL:
return ctables_pcexpr_evaluate_category (ctx, &cv);
}
+ case CTPO_CAT_STRING:
+ {
+ int width = var_get_width (ctx->section->nests[ctx->pc_a]->vars[ctx->pc_a_idx]);
+ char *s = NULL;
+ if (width > e->string.length)
+ {
+ s = xmalloc (width);
+ buf_copy_rpad (s, width, e->string.string, e->string.length, ' ');
+ }
+ struct ctables_cell_value cv = {
+ .category = ctables_find_category_for_postcompute (ctx->section->table->ctables->dict, ctx->cats, ctx->parse_format, e),
+ .value = { .s = CHAR_CAST (uint8_t *, s ? s : e->string.string) },
+ };
+ assert (cv.category != NULL);
+ double retval = ctables_pcexpr_evaluate_category (ctx, &cv);
+ free (s);
+ return retval;
+ }
+
case CTPO_ADD:
return ctables_pcexpr_evaluate_nonterminal (ctx, e, 2, ctpo_add);
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
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.
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 .])
])
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 ¬yes=EXPR(['No']+['DontKnow']+['Refused'])
+ /PPROPERTIES ¬yes LABEL='Not Yes' HIDESOURCECATS=YES
+ /TABLE licensed
+ /CATEGORIES VARIABLES=licensed ['Yes', ¬yes, 'No', 'DontKnow', 'Refused'].
+CTABLES
+ /PCOMPUTE ¬yes=EXPR(['No']+['DontKnow']+['Refused'])
+ /PPROPERTIES ¬yes LABEL='Not Yes' HIDESOURCECATS=YES
+ /TABLE licensed
+ /CATEGORIES VARIABLES=licensed ['Yes', ¬yes, '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],