Skip to content

Commit

Permalink
#98: update round to round_sas
Browse files Browse the repository at this point in the history
  • Loading branch information
Kangjie Zhang committed Apr 21, 2023
1 parent 4ad0663 commit d5d139f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
17 changes: 17 additions & 0 deletions R/adam_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,20 @@ format_dcsreas <- function(x) {
x == "LACK OF EFFICACY" ~ "Lack of Efficacy"
)
}

#' Round the value based on SAS rounding convention
#'
#' `round_sas` rounds the values in its first argument to the specified number
#' of decimal places (default 0) (align SAS rounding convention)
#'
#' @inheritParams round_sas
#'
#' @export
round_sas <- function(x, digits = 0) {
# x is the value to be rounded
# digits is the precision of the rounding
scale <- 10^digits
y <- trunc(x * scale + sign(x) * 0.5) / scale
# Return the rounded number
return(y)
}
Binary file modified submission/datasets/adsl.xpt
Binary file not shown.
10 changes: 5 additions & 5 deletions submission/programs/adsl.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ adsl00 <- dm %>%
# dosing
left_join(ex_dose, by = c("STUDYID", "USUBJID")) %>%
select(-cnt) %>%
mutate(AVGDD = round(CUMDOSE / TRTDURD, digits = 1))
mutate(AVGDD = round_sas(CUMDOSE / TRTDURD, digits = 1))

# Demographic grouping ----------------------------------------------------
# distinct(adsl_prod[which(adsl_prod$SITEGR1 == "900"), c("SITEID", "SITEGR1")])
Expand Down Expand Up @@ -224,11 +224,11 @@ adsl04 <- adsl03 %>%

vs00 <- vs %>%
filter((VSTESTCD == "HEIGHT" & VISITNUM == 1) | (VSTESTCD == "WEIGHT" & VISITNUM == 3)) %>%
mutate(AVAL = round(VSSTRESN, digits = 1)) %>%
mutate(AVAL = round_sas(VSSTRESN, digits = 1)) %>%
select(STUDYID, USUBJID, VSTESTCD, AVAL) %>%
pivot_wider(names_from = VSTESTCD, values_from = AVAL, names_glue = "{VSTESTCD}BL") %>%
mutate(
BMIBL = round(WEIGHTBL / (HEIGHTBL / 100)^2, digits = 1)
BMIBL = round_sas(WEIGHTBL / (HEIGHTBL / 100)^2, digits = 1)
) %>%
create_cat_var(adsl_spec, BMIBL, BMIBLGR1)

Expand Down Expand Up @@ -257,7 +257,7 @@ visnumen <- sv %>%
group_by(STUDYID, USUBJID) %>%
slice(n()) %>%
ungroup() %>%
mutate(VISNUMEN = ifelse(round(VISITNUM, digits = 0) == 13, 12, round(VISITNUM, digits = 0))) %>%
mutate(VISNUMEN = ifelse(round_sas(VISITNUM, digits = 0) == 13, 12, round_sas(VISITNUM, digits = 0))) %>%
select(STUDYID, USUBJID, VISNUMEN)

disonsdt <- mh %>%
Expand All @@ -280,7 +280,7 @@ adsl06 <- adsl05 %>%
add_one = TRUE
) %>%
mutate(
DURDIS = round(DURDIS, digits = 1)
DURDIS = round_sas(DURDIS, digits = 1)
) %>%
create_cat_var(adsl_spec, DURDIS, DURDSGR1) %>%
derive_vars_dt(
Expand Down

0 comments on commit d5d139f

Please # to comment.