derive_seq: Derive the sequence number ('–SEQ') variable

View source: R/derive_seq.R

derive_seqR Documentation

Derive the sequence number (--SEQ) variable

Description

derive_seq() creates a new identifier variable: the sequence number (--SEQ).

This function adds a newly derived variable to tgt_dat, namely the sequence number (--SEQ) whose name is the one provided in tgt_var. An integer sequence is generated that uniquely identifies each record within the domain.

Prior to the derivation of tgt_var, the data frame tgt_dat is sorted according to grouping variables indicated in rec_vars.

Usage

derive_seq(
  tgt_dat,
  tgt_var,
  rec_vars,
  sbj_vars = sdtm.oak::sbj_vars(),
  start_at = 1L
)

Arguments

tgt_dat

The target dataset, a data frame.

tgt_var

The target SDTM variable: a single string indicating the name of the sequence number (--SEQ) variable, e.g. "DSSEQ". Note that supplying a name not ending in "SEQ" will raise a warning.

rec_vars

A character vector of record-level identifier variables.

sbj_vars

A character vector of subject-level identifier variables.

start_at

The sequence numbering starts at this value (default is 1).

Value

Returns the data frame supplied in tgt_dat with the newly derived variable, i.e. the sequence number (--SEQ), whose name is that passed in tgt_var. This variable is of type integer.

Examples

# A VS raw data set example
(vs <- read_domain_example("vs"))

# Derivation of VSSEQ
rec_vars <- c("STUDYID", "USUBJID", "VSTESTCD", "VSDTC", "VSTPTNUM")
derive_seq(tgt_dat = vs, tgt_var = "VSSEQ", rec_vars = rec_vars)

# An APSC raw data set example
(apsc <- read_domain_example("apsc"))

# Derivation of APSEQ
derive_seq(
  tgt_dat = apsc,
  tgt_var = "APSEQ",
  rec_vars = c("STUDYID", "RSUBJID", "SCTESTCD"),
  sbj_vars = c("STUDYID", "RSUBJID")
)

sdtm.oak documentation built on April 3, 2025, 9:37 p.m.