A trainee discovered when creating a demographic table that the set_order_count_method("byvarn") seems to mess up when combined with a total row.
Context in our training we show solving this by creating an AGEGR1 factor, but this user saw that AGEGR1N is available in ADSL and wanted to change the default sort to us the VARN.
Our original code solution from our training (with AGEGR1 as factor):
add_layer(
group_count(AGEGR1, by = "Age Categories n (%)") %>%
add_total_row(fmt=f_str("xx",n), count_missings=FALSE, sort_value=-Inf) %>%
set_total_row_label("n") %>%
set_missing_count(f_str("xx", n), denom_ignore=TRUE, "Missing" = NA)
) %>%
Users code by VARN:
l_agec <- group_count(t, AGEGR1, by = "Age Categories n (%)") %>%
set_order_count_method("byvarn") %>%
add_total_row(fmt = f_str("xx",n), count_missings = FALSE, sort_value=-Inf) %>%
set_total_row_label("n") %>%
set_missing_count(fmt = f_str("xx", n), denom_ignore = TRUE, "Missing" = NA)
user's result - see ORD LAYER 2 - see example 1

user's result if total row is not included - see example 2

Mike Stackhouse thinks this is a bug: "This looks like a bug. I’ve been doing some updates so now is a good time to file it. Seems like the total row is accidentally setting the entire set of values to its sort value."
Full code for original solution to show context.
demog1_answer.txt
A trainee discovered when creating a demographic table that the set_order_count_method("byvarn") seems to mess up when combined with a total row.
Context in our training we show solving this by creating an AGEGR1 factor, but this user saw that AGEGR1N is available in ADSL and wanted to change the default sort to us the VARN.
Our original code solution from our training (with AGEGR1 as factor):
add_layer(
group_count(AGEGR1, by = "Age Categories n (%)") %>%
add_total_row(fmt=f_str("xx",n), count_missings=FALSE, sort_value=-Inf) %>%
set_total_row_label("n") %>%
set_missing_count(f_str("xx", n), denom_ignore=TRUE, "Missing" = NA)
) %>%
Users code by VARN:
l_agec <- group_count(t, AGEGR1, by = "Age Categories n (%)") %>%
set_order_count_method("byvarn") %>%
add_total_row(fmt = f_str("xx",n), count_missings = FALSE, sort_value=-Inf) %>%
set_total_row_label("n") %>%
set_missing_count(fmt = f_str("xx", n), denom_ignore = TRUE, "Missing" = NA)
user's result - see ORD LAYER 2 - see example 1
user's result if total row is not included - see example 2
Mike Stackhouse thinks this is a bug: "This looks like a bug. I’ve been doing some updates so now is a good time to file it. Seems like the total row is accidentally setting the entire set of values to its sort value."
Full code for original solution to show context.
demog1_answer.txt