+ while (casegrouper_get_next_group (split_grouper, &split_group))
+ {
+ struct subcase ordering;
+ struct casereader *ordered;
+ struct casegrouper *by_grouper;
+ struct casereader *by_group;
+
+ /* Sort this split group by the BY variables as primary
+ keys and the rank variable as secondary key. */
+ subcase_init_vars (&ordering, group_vars, n_group_vars);
+ subcase_add_var (&ordering, src_vars[i],
+ subcase_get_direction (sc, i));
+ ordered = sort_execute (split_group, &ordering);
+ subcase_destroy (&ordering);
+
+ /* Rank the rank variable within this split group. */
+ by_grouper = casegrouper_create_vars (ordered,
+ group_vars, n_group_vars);
+ while (casegrouper_get_next_group (by_grouper, &by_group))
+ {
+ /* Rank the rank variable within this BY group
+ within the split group. */
+
+ rank_sorted_file (by_group, output, d, rank_specs, n_rank_specs,
+ i, src_vars[i]);
+ }
+ ok = casegrouper_destroy (by_grouper) && ok;
+ }
+ ok = casegrouper_destroy (split_grouper);
+ ok = proc_commit (ds) && ok;
+ ok = (dataset_set_source (ds, casewriter_make_reader (output))
+ && ok);
+ if (!ok)
+ break;
+ }
+
+ return ok;