/* SDTM DM and VS to ADSL and ADVS: the derivations, value-level metadata (one description per PARAMCD) and code lists, as define.xml needs them */ options lineage; data dm; input usubjid $ armcd $ age sex $; datalines; 01-001 A 54 F 01-002 P 67 M 01-003 A 71 M 01-004 P 45 F ; run; data vs; input usubjid $ vstestcd $ vsstresn visitnum; datalines; 01-001 WEIGHT 61.2 1 01-001 HEIGHT 165 1 01-002 WEIGHT 88.0 1 01-002 HEIGHT 178 1 01-003 WEIGHT 79.5 1 01-003 HEIGHT 172 1 01-004 WEIGHT 55.1 1 01-004 HEIGHT 160 1 ; run; data adsl; set dm; length trt01p $8 agegr1 $5; if armcd = 'A' then do; trt01p = 'Drug A'; trt01pn = 1; end; else do; trt01p = 'Placebo'; trt01pn = 0; end; if age < 65 then do; agegr1 = '<65'; agegr1n = 1; end; else do; agegr1 = '>=65'; agegr1n = 2; end; label trt01p = 'Planned Treatment' agegr1 = 'Pooled Age Group 1'; run; proc sort data=vs; by usubjid; run; data advs1; merge vs(in=invs) adsl(keep=usubjid trt01p trt01pn); by usubjid; if invs; length paramcd $8 param $20; paramcd = vstestcd; if vstestcd = 'WEIGHT' then param = 'Weight (kg)'; else if vstestcd = 'HEIGHT' then param = 'Height (cm)'; aval = vsstresn; avisitn = visitnum; drop vstestcd vsstresn visitnum; run; /* a derived parameter: BMI from each subject's weight and height */ data bmi; merge advs1(where=(paramcd = 'WEIGHT') rename=(aval=weight)) advs1(where=(paramcd = 'HEIGHT') keep=usubjid paramcd aval rename=(aval=height)); by usubjid; paramcd = 'BMI'; param = 'BMI (kg/m2)'; aval = round(weight / (height / 100)**2, 0.1); drop weight height; run; data advs; set advs1 bmi; by usubjid; run; /* the report, three metadata data sets, and the whole model as JSON (in the WORK folder here; give a path of your own to keep it) */ proc lineage data=work.advs out=advs_meta outvalues=advs_vlm outcodes=advs_codes json="%sysfunc(pathname(work))/advs_lineage.json"; run; proc print data=advs_vlm noobs; var name value origin derivation; run; proc print data=advs_codes noobs; var name order value closed pairname pairvalue; run;