CROSSTABS: Handle case where all cases in a crosstabulation are missing.
[pspp-builds.git] / src / language / stats / crosstabs.q
index be096bc4056d0c155242b53e1c153494dd4786fb..189e718220c7311d08aae289edd2dfccb06e526c 100644 (file)
@@ -908,9 +908,7 @@ static void table_value_missing (struct crosstabs_proc *proc,
 static void delete_missing (struct pivot_table *);
 static void build_matrix (struct pivot_table *);
 
-/* Output pivot table beginning at PB and continuing until PE,
-   exclusive.  For efficiency, *MATP is a pointer to a matrix that can
-   hold *MAXROWS entries. */
+/* Output pivot table PT in the context of PROC. */
 static void
 output_pivot_table (struct crosstabs_proc *proc, struct pivot_table *pt)
 {
@@ -924,6 +922,24 @@ output_pivot_table (struct crosstabs_proc *proc, struct pivot_table *pt)
 
   enum_var_values (pt, COL_VAR, &pt->cols, &pt->n_cols, proc->descending);
 
+  if (pt->n_cols == 0)
+    {
+      struct string vars;
+      int i;
+
+      ds_init_cstr (&vars, var_get_name (pt->vars[0]));
+      for (i = 1; i < pt->n_vars; i++)
+        ds_put_format (&vars, " * %s", var_get_name (pt->vars[i]));
+
+      /* TRANSLATORS: The %s here describes a crosstabulation.  It takes the
+         form "var1 * var2 * var3 * ...".  */
+      msg (SW, _("Crosstabulation %s contained no non-missing cases."),
+           ds_cstr (&vars));
+
+      ds_destroy (&vars);
+      return;
+    }
+
   if (proc->cells)
     table = create_crosstab_table (proc, pt);
   if (proc->statistics & (1u << CRS_ST_CHISQ))