## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ## ----eval=FALSE, echo=TRUE---------------------------------------------------- # library(sassy) # # # Open the log # log_open("Example1.log") # # # Write to the log # put("Here is something to send to the log.") # # # Close the log # log_close() # ## ----eval=FALSE, echo=TRUE---------------------------------------------------- # library(sassy) # # # Define library # libname(sdtm, "./data", "csv") ## ----eval=FALSE, echo=TRUE---------------------------------------------------- # library(sassy) # # #Create libname # libname(sdtm, "./data", "csv") # # # Copy DM dataset # dat <- sdtm$DM # # # Create user-defined format # fmt_sex <- value(condition(is.na(x), "Missing"), # condition(x == "M", "Male"), # condition(x == "F", "Female"), # condition(TRUE, "Other")) # # # Create a new column of formatted values # dat$SEXF <- fapply(dat$SEX, fmt_sex) # # # View a few rows of data # print(dat[1:5, c("USUBJID", "SEX", "SEXF")]) # # # A tibble: 5 x 3 # # USUBJID SEX SEXF # # # # 1 ABC-01-049 M Male # # 2 ABC-01-050 M Male # # 3 ABC-01-051 M Male # # 4 ABC-01-052 F Female # # 5 ABC-01-053 F Female # ## ----eval=FALSE, echo=TRUE---------------------------------------------------- # library(sassy) # # #Create libname # libname(sdtm, "./data", "csv") # # # # Perform data step # dm_mod <- datastep(sdtm$DM, keep = c("USUBJID", "AGE", "AGECAT"), { # if (AGE >= 18 & AGE <= 24) # AGECAT <- "18 to 24" # else if (AGE >= 25 & AGE <= 44) # AGECAT <- "25 to 44" # else if (AGE >= 45 & AGE <= 64) # AGECAT <- "45 to 64" # else if (AGE >= 65) # AGECAT <- ">= 65" # }) # # # Print dm_mod to console # print(dm_mod) # # # A tibble: 87 x 3 # # USUBJID AGE AGECAT # # # # 1 ABC-01-049 39 25 to 44 # # 2 ABC-01-050 47 45 to 64 # # 3 ABC-01-051 34 25 to 44 # # 4 ABC-01-052 45 45 to 64 # # 5 ABC-01-053 26 25 to 44 # # 6 ABC-01-054 44 25 to 44 # # 7 ABC-01-055 47 45 to 64 # # 8 ABC-01-056 31 25 to 44 # # 9 ABC-01-113 74 >= 65 # # 10 ABC-01-114 72 >= 65 # # # ... with 77 more rows ## ----eval=FALSE, echo=TRUE---------------------------------------------------- # library(sassy) # # # Define data library # libname(sdtm, "./data", "csv") # # # Generate Frequencies # res <- proc_freq(sdtm$DM, # tables = c("ARM", "SEX", "SEX * ARM"), # output = "report") # # # Generate Means and append to Frequencies # res[["AGE"]] <- proc_means(dat, var = "AGE", # class = "ARM", # output = "report") # # # Print everything to viewer # proc_print(res, titles = "Analysis of Demographics Dataset") ## ----eval=FALSE, echo=TRUE---------------------------------------------------- # library(sassy) # # # Define data library # libname(sdtm, "./data", "csv") # # # Create report content # tbl <- create_table(sdtm$DM) |> # define(RACE, width = 2.5) |> # define(ETHNIC, width = 2.5) |> # define(USUBJID, id_var = TRUE) # # # Create report and add content # rpt <- create_report("./output/example.pdf", font = "Courier", # output_type = "PDF") |> # page_header("Sponsor: Company", "Study: ABC") |> # titles("Listing 1.0", "Sample Demographics Data") |> # add_content(tbl) |> # page_footer(Sys.time(), "CONFIDENTIAL", "Page [pg] of [tpg]") # # # Write out the report # write_report(rpt) #