CDISC dataset migration
SDTM Programming in R for SAS Teams
Explore practical SAS-to-R patterns for SDTM data preparation, then validate controlled terminology, date handling, metadata, and domain conformance against your study standards.
Try the SAS to R converterExample
Map treatment, controlled terminology, and start dates for an SDTM CM domain
SAS
proc format;
value $route_ct
'PO', 'ORAL' = 'ORAL'
'IV', 'INTRAVENOUS' = 'INTRAVENOUS'
other = ' ';
run;
data cm;
set raw.cm;
length cmtrt $200 cmroute $40 cmstdtc $19;
cmtrt = cmtrt_raw;
cmroute = put(upcase(cmroute_raw), $route_ct.);
if not missing(cmstdt_raw) then
cmstdtc = put(input(cmstdt_raw, yymmdd10.), e8601da.);
run;R
library(sdtm.oak)
cm <- assign_no_ct(
tgt_var = 'CMTRT',
raw_dat = raw_cm,
raw_var = 'CMTRT_RAW',
id_vars = oak_id_vars()
) |>
assign_ct(
tgt_var = 'CMROUTE',
raw_dat = raw_cm,
raw_var = 'CMROUTE_RAW',
ct_spec = study_ct,
ct_clst = 'C66729',
id_vars = oak_id_vars()
) |>
assign_datetime(
tgt_var = 'CMSTDTC',
raw_dat = raw_cm,
raw_var = 'CMSTDT_RAW',
raw_fmt = 'y-m-d',
raw_unk = c('UN', 'UNK'),
id_vars = oak_id_vars()
)What to validate after conversion
- Handle partial and ISO-format dates deliberately.
- Keep controlled terminology mappings explicit and reviewable.
- Validate required variables, metadata, and domain-level rules.
Always validate source keys, controlled terminology, date precision, metadata, and domain rules against the SAS output and your study standards.
Frequently asked questions
How should SAS formats be represented in R for SDTM?
Use explicit parsing and formatting rules, plus documented controlled-terminology mappings. Do not assume a SAS display format carries all of the required semantic meaning.
What should be checked after converting an SDTM derivation?
Review required variables, variable attributes, controlled terminology, date precision, key uniqueness, sorting rules, and traceability to the defined source data.
Related SAS to R resources
Clinical workflows
SAS to R for Clinical Trial Programming
SAS2R.ai helps clinical programming teams begin translating deterministic SAS logic into readable R while preserving the review, QC, traceability, and validation work required by their processes.
CDISC datasets
ADaM Programming in R for SAS Teams
Translate common ADaM derivation patterns from SAS to R while keeping timing, baseline windows, population flags, and sponsor-specific conventions visible for review.