SAS: date minus date, INTCK('day', ...), CDISC --DY
CDISC --DY has no day 0. The reference start date is day 1. Dates before the reference stay negative and are not shifted. Raw subtraction is not --DY on or after the reference date.
Quick reference
library(dplyr)# CDISC --DY has no day 0. The reference date is day 1, not day 0.if_else(date < rfstdt, date - rfstdt, date - rfstdt +1)# same rule, no branch:as.integer(date - rfstdt) +as.integer(date >= rfstdt)
R
SAS
date - rfstdt
date minus date (raw, includes day 0)
if_else(date < rfstdt, date - rfstdt, date - rfstdt + 1)
Three traps: raw subtraction is not --DY. On the reference date the raw diff is 0; --DY is 1. Dates before the reference stay negative and do not shift. Missing either date must stay missing, not become day 0.
Worked examples below.
Raw diff versus --DY
Five lab dates around one reference start: two before, the reference date, two after.
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
The day before and the day after the reference are not symmetric. SAS date arithmetic returns the raw column. --DY is the LBDY column.
ImportantThere is no day 0
date - rfstdt on the reference date is 0. --DY on that date is 1. Every date on or after the reference is shifted by +1. Dates before the reference remain a negative offset. The raw diff labels the first treatment day as 0 and offsets every later day by one.
STD-001-0001 study days: -1, 1, 2. STD-001-0002: 1, then NA. Do not replace missing dates with 0. CDISC leaves --DY missing when either date is missing.
INTCK('day', rfstdt, date) in SAS is the raw interval, not --DY. Apply the same +1 on and after the reference date.