Skip to contents

Adds a record for BMI/Body Mass Index using Weight and Height each by group (e.g., subject and visit) where the source parameters are available.


  set_values_to = vars(PARAMCD = "BMI"),
  weight_code = "WEIGHT",
  height_code = "HEIGHT",
  filter = NULL



Input dataset

The variables specified by the by_vars parameter, PARAMCD, and AVAL are expected.

The variable specified by by_vars and PARAMCD must be a unique key of the input dataset after restricting it by the filter condition (filter parameter) and to the parameters specified by weight_code and height_code.


Grouping variables

For each group defined by by_vars an observation is added to the output dataset. Only variables specified in by_vars will be populated in the newly created records.

Permitted Values: list of variables


Variables to be set

The specified variables are set to the specified values for the new observations. For example vars(PARAMCD = "MAP") defines the parameter code for the new parameter.

Permitted Values: List of variable-value pairs


WEIGHT parameter code

The observations where PARAMCD equals the specified value are considered as the WEIGHT. It is expected that WEIGHT is measured in kg

Permitted Values: character value


HEIGHT parameter code

The observations where PARAMCD equals the specified value are considered as the HEIGHT. It is expected that HEIGHT is measured in cm

Permitted Values: character value


An expression providing the unit of the parameter

The result is used to check the units of the input parameters.

Permitted Values: A variable of the input dataset or a function call


Filter condition

The specified condition is applied to the input dataset before deriving the new parameter, i.e., only observations fulfilling the condition are taken into account.

Permitted Values: a condition


The input dataset with the new parameter added. Note, a variable will only be populated in the new parameter rows if it is specified in by_vars.


The analysis value of the new parameter is derived as $$BMI = \frac{WEIGHT}{HEIGHT^2}$$


Pavan Kumar



advs <- tribble(
  "01-701-1015", "HEIGHT", "Height (cm)", 147,   "SCREENING",
  "01-701-1015", "WEIGHT", "Weight (kg)", 54.0,  "SCREENING",
  "01-701-1015", "WEIGHT", "Weight (kg)", 54.4,  "BASELINE",
  "01-701-1015", "WEIGHT", "Weight (kg)", 53.1,  "WEEK 2",
  "01-701-1028", "HEIGHT", "Height (cm)", 163,   "SCREENING",
  "01-701-1028", "WEIGHT", "Weight (kg)", 78.5,  "SCREENING",
  "01-701-1028", "WEIGHT", "Weight (kg)", 80.3,  "BASELINE",
  "01-701-1028", "WEIGHT", "Weight (kg)", 80.7,  "WEEK 2"

  by_vars = vars(USUBJID, AVISIT),
  weight_code = "WEIGHT",
  height_code = "HEIGHT",
  set_values_to = vars(
    PARAMCD = "BMI",
    PARAM = "Body Mass Index (kg/m^2)"
  get_unit_expr = extract_unit(PARAM)
#> # A tibble: 10 x 5
#>    USUBJID     PARAMCD PARAM                     AVAL AVISIT   
#>    <chr>       <chr>   <chr>                    <dbl> <chr>    
#>  1 01-701-1015 HEIGHT  Height (cm)              147   SCREENING
#>  2 01-701-1015 WEIGHT  Weight (kg)               54   SCREENING
#>  3 01-701-1015 WEIGHT  Weight (kg)               54.4 BASELINE 
#>  4 01-701-1015 WEIGHT  Weight (kg)               53.1 WEEK 2   
#>  5 01-701-1028 HEIGHT  Height (cm)              163   SCREENING
#>  6 01-701-1028 WEIGHT  Weight (kg)               78.5 SCREENING
#>  7 01-701-1028 WEIGHT  Weight (kg)               80.3 BASELINE 
#>  8 01-701-1028 WEIGHT  Weight (kg)               80.7 WEEK 2   
#>  9 01-701-1015 BMI     Body Mass Index (kg/m^2)  25.0 SCREENING
#> 10 01-701-1028 BMI     Body Mass Index (kg/m^2)  29.5 SCREENING