Clinwright Public work of Helper Software LLC · free Start free

ADMH

Medical History Analysis Dataset

OCCURRENCE DATA STRUCTURE · one record per subject per medical history term · keys STUDYID, USUBJID, MHSEQ

Variables

VariableLabelTypeLengthDerivation
STUDYIDStudy IdentifiertextPredecessor MH.STUDYID
USUBJIDUnique Subject IdentifiertextPredecessor MH.USUBJID
SUBJIDSubject Identifier for the StudytextPredecessor ADSL.SUBJID
SITEIDStudy Site IdentifiertextPredecessor ADSL.SITEID
AGEAgeinteger8Predecessor ADSL.AGE
SEXSextextPredecessor ADSL.SEX
RACERacetextPredecessor ADSL.RACE
SAFFLSafety Population FlagtextPredecessor ADSL.SAFFL
TRT01PPlanned Treatment for Period 01textPredecessor ADSL.TRT01P
TRT01AActual Treatment for Period 01textPredecessor ADSL.TRT01A
TRTSDTDate of First Exposure to Treatmentinteger8Predecessor ADSL.TRTSDT
MHSEQSequence Numberinteger8Predecessor MH.MHSEQ
MHTERMReported Term for the Medical HistorytextPredecessor MH.MHTERM
MHDECODDictionary-Derived TermtextPredecessor MH.MHDECOD
MHBODSYSBody System or Organ ClasstextPredecessor MH.MHBODSYS
MHSTDTCStart Date/Time of Medical History EventtextPredecessor MH.MHSTDTC
ASTDTAnalysis Start Dateinteger8MH.MHSTDTC converted to a numeric SAS date; a partial date is imputed to the first day (of the month, or of the year when the month is missing too).
ASTDTFAnalysis Start Date Imputation FlagtextThe level of imputation of ASTDT from MH.MHSTDTC: D when the day was imputed, M when the month and day were.

Program admh.sas

Version 1, written from Clinwright's patterns, 2026-10-17, checks passed.

/*==== 00-header ====*/
/*----------------------------------------------------------------------------
  Data set : ADMH (Medical History Analysis Dataset)
  Reporting effort : CSR
  SDTM     : MH
  ADaM     : ADSL
  The header and the finalize step follow from the specification.
----------------------------------------------------------------------------*/
libname sdtm "/work/sdtm" access=readonly;
libname adam "/work/adam";
options validvarname=upcase nofmterr msglevel=i;

/*==== 10-inputs ====*/
/* The MH records, with the subject's TRTSDT, TRTEDT, SUBJID, SITEID, AGE, SEX, RACE, SAFFL, TRT01P, TRT01A from ADSL. */
proc sort data=sdtm.mh(keep=studyid usubjid mhseq mhterm mhdecod mhbodsys mhstdtc) out=work._ds; by usubjid; run;
proc sort data=adam.adsl(keep=usubjid trtsdt trtedt subjid siteid age sex race saffl trt01p trt01a) out=work._adsl; by usubjid; run;
data work._ds;
  merge work._ds(in=_in) work._adsl;
  by usubjid;
  if _in;
run;

/*==== 30-timing ====*/
/* ASTDT: MH.MHSTDTC as a SAS date; a date without its day (or month) takes the first one. */
data work._ds;
  set work._ds;
  length _dtc $10;
  _dtc = mhstdtc; /* (its first 10 characters: SUBSTR would complain of a shorter variable) */
  if length(_dtc) = 10 then astdt = input(_dtc, ?? yymmdd10.);

  else if length(_dtc) = 7 then do; /* yyyy-mm */
    astdt = input(cats(_dtc, '-01'), ?? yymmdd10.);

  end;

  else if length(_dtc) = 4 then do; /* yyyy */
    astdt = mdy(1, 1, input(_dtc, ?? 4.));

  end;


  format astdt date9.;
  drop _dtc;
run;

/* ASTDTF: what of ASTDT was imputed from MH.MHSTDTC (set where ASTDT is imputed; see LSP-TIMING-DT). */
data work._ds;
  set work._ds;
  length astdtf $1;
  if astdt > . then select (length(substr(mhstdtc, 1, 10)));
    when (10) astdtf = '';
    when (7) astdtf = 'D';
    when (4) astdtf = 'M';
    otherwise astdtf = '';
  end;
run;

/*==== 89-final ====*/
/* The data set as derived; the finalize step keeps the specification's variables. */
data work._final;
  set work._ds;
run;

/*==== 90-finalize ====*/
/* 90-finalize: from the specification; the variables, their order and attributes are not changed here. */
/* The text variables the specification gives no length: as long as their longest value (at least 1). */
%let _len1 = 1; %let _len2 = 1; %let _len3 = 1; %let _len4 = 1; %let _len5 = 1; %let _len6 = 1; %let _len7 = 1; %let _len8 = 1; %let _len9 = 1; %let _len10 = 1; %let _len11 = 1; %let _len12 = 1; %let _len13 = 1; %let _len14 = 1;
data _null_;
  length _ren _asg _siz $32767;
  _dsid = open('work._final');
  if varnum(_dsid, 'STUDYID') > 0 then do; _ren = catx(' ', _ren, 'STUDYID=_rz1'); _asg = catx(' ', _asg, 'STUDYID = _rz1;');
    _siz = catx(' ', _siz, '_len1 = max(_len1, lengthn(STUDYID));'); end;
  if varnum(_dsid, 'USUBJID') > 0 then do; _ren = catx(' ', _ren, 'USUBJID=_rz2'); _asg = catx(' ', _asg, 'USUBJID = _rz2;');
    _siz = catx(' ', _siz, '_len2 = max(_len2, lengthn(USUBJID));'); end;
  if varnum(_dsid, 'SUBJID') > 0 then do; _ren = catx(' ', _ren, 'SUBJID=_rz3'); _asg = catx(' ', _asg, 'SUBJID = _rz3;');
    _siz = catx(' ', _siz, '_len3 = max(_len3, lengthn(SUBJID));'); end;
  if varnum(_dsid, 'SITEID') > 0 then do; _ren = catx(' ', _ren, 'SITEID=_rz4'); _asg = catx(' ', _asg, 'SITEID = _rz4;');
    _siz = catx(' ', _siz, '_len4 = max(_len4, lengthn(SITEID));'); end;
  if varnum(_dsid, 'SEX') > 0 then do; _ren = catx(' ', _ren, 'SEX=_rz5'); _asg = catx(' ', _asg, 'SEX = _rz5;');
    _siz = catx(' ', _siz, '_len5 = max(_len5, lengthn(SEX));'); end;
  if varnum(_dsid, 'RACE') > 0 then do; _ren = catx(' ', _ren, 'RACE=_rz6'); _asg = catx(' ', _asg, 'RACE = _rz6;');
    _siz = catx(' ', _siz, '_len6 = max(_len6, lengthn(RACE));'); end;
  if varnum(_dsid, 'SAFFL') > 0 then do; _ren = catx(' ', _ren, 'SAFFL=_rz7'); _asg = catx(' ', _asg, 'SAFFL = _rz7;');
    _siz = catx(' ', _siz, '_len7 = max(_len7, lengthn(SAFFL));'); end;
  if varnum(_dsid, 'TRT01P') > 0 then do; _ren = catx(' ', _ren, 'TRT01P=_rz8'); _asg = catx(' ', _asg, 'TRT01P = _rz8;');
    _siz = catx(' ', _siz, '_len8 = max(_len8, lengthn(TRT01P));'); end;
  if varnum(_dsid, 'TRT01A') > 0 then do; _ren = catx(' ', _ren, 'TRT01A=_rz9'); _asg = catx(' ', _asg, 'TRT01A = _rz9;');
    _siz = catx(' ', _siz, '_len9 = max(_len9, lengthn(TRT01A));'); end;
  if varnum(_dsid, 'MHTERM') > 0 then do; _ren = catx(' ', _ren, 'MHTERM=_rz10'); _asg = catx(' ', _asg, 'MHTERM = _rz10;');
    _siz = catx(' ', _siz, '_len10 = max(_len10, lengthn(MHTERM));'); end;
  if varnum(_dsid, 'MHDECOD') > 0 then do; _ren = catx(' ', _ren, 'MHDECOD=_rz11'); _asg = catx(' ', _asg, 'MHDECOD = _rz11;');
    _siz = catx(' ', _siz, '_len11 = max(_len11, lengthn(MHDECOD));'); end;
  if varnum(_dsid, 'MHBODSYS') > 0 then do; _ren = catx(' ', _ren, 'MHBODSYS=_rz12'); _asg = catx(' ', _asg, 'MHBODSYS = _rz12;');
    _siz = catx(' ', _siz, '_len12 = max(_len12, lengthn(MHBODSYS));'); end;
  if varnum(_dsid, 'MHSTDTC') > 0 then do; _ren = catx(' ', _ren, 'MHSTDTC=_rz13'); _asg = catx(' ', _asg, 'MHSTDTC = _rz13;');
    _siz = catx(' ', _siz, '_len13 = max(_len13, lengthn(MHSTDTC));'); end;
  if varnum(_dsid, 'ASTDTF') > 0 then do; _ren = catx(' ', _ren, 'ASTDTF=_rz14'); _asg = catx(' ', _asg, 'ASTDTF = _rz14;');
    _siz = catx(' ', _siz, '_len14 = max(_len14, lengthn(ASTDTF));'); end;
  _rc = close(_dsid);
  if _ren ne '' then _ren = cats('(rename=(', _ren, '))');
  call symputx('_ren', _ren);
  call symputx('_asg', _asg);
  call symputx('_siz', _siz);
run;
data _null_;
  set work._final end=_end;
  retain _len1 1 _len2 1 _len3 1 _len4 1 _len5 1 _len6 1 _len7 1 _len8 1 _len9 1 _len10 1 _len11 1 _len12 1 _len13 1 _len14 1;
  &_siz
  if _end then do;
    call symputx('_len1', _len1);
    call symputx('_len2', _len2);
    call symputx('_len3', _len3);
    call symputx('_len4', _len4);
    call symputx('_len5', _len5);
    call symputx('_len6', _len6);
    call symputx('_len7', _len7);
    call symputx('_len8', _len8);
    call symputx('_len9', _len9);
    call symputx('_len10', _len10);
    call symputx('_len11', _len11);
    call symputx('_len12', _len12);
    call symputx('_len13', _len13);
    call symputx('_len14', _len14);
  end;
run;
data adam.admh(label="Medical History Analysis Dataset");
  attrib
    STUDYID  length=$&_len1 label="Study Identifier"
    USUBJID  length=$&_len2 label="Unique Subject Identifier"
    SUBJID   length=$&_len3 label="Subject Identifier for the Study"
    SITEID   length=$&_len4 label="Study Site Identifier"
    AGE      length=8 label="Age"
    SEX      length=$&_len5 label="Sex"
    RACE     length=$&_len6 label="Race"
    SAFFL    length=$&_len7 label="Safety Population Flag"
    TRT01P   length=$&_len8 label="Planned Treatment for Period 01"
    TRT01A   length=$&_len9 label="Actual Treatment for Period 01"
    TRTSDT   length=8 label="Date of First Exposure to Treatment" format=DATE9.
    MHSEQ    length=8 label="Sequence Number"
    MHTERM   length=$&_len10 label="Reported Term for the Medical History"
    MHDECOD  length=$&_len11 label="Dictionary-Derived Term"
    MHBODSYS length=$&_len12 label="Body System or Organ Class"
    MHSTDTC  length=$&_len13 label="Start Date/Time of Medical History Event"
    ASTDT    length=8 label="Analysis Start Date" format=DATE9.
    ASTDTF   length=$&_len14 label="Analysis Start Date Imputation Flag"
  ;
  set work._final&_ren;
  &_asg
  keep STUDYID USUBJID SUBJID SITEID AGE SEX RACE SAFFL TRT01P TRT01A TRTSDT MHSEQ MHTERM MHDECOD MHBODSYS MHSTDTC ASTDT ASTDTF;
run;
proc sort data=adam.admh; by STUDYID USUBJID MHSEQ; run;

Data (first 20 of 775 records, simulated)

STUDYIDUSUBJIDSUBJIDSITEIDAGESEXRACESAFFLTRT01PTRT01ATRTSDTMHSEQMHTERMMHDECODMHBODSYSMHSTDTCASTDTASTDTF
ONCO-EXONCO-EX-7010011HYPOTHYROIDISMHypothyroidismEndocrine disorders2007-082007-08-01D
ONCO-EXONCO-EX-7010012TYPE 2 DIABETESType 2 diabetes mellitusMetabolism and nutrition disorders2018-102018-10-01D
ONCO-EXONCO-EX-70100370100370158MWHITEYStandard of CareStandard of Care2022-03-171HIGH CHOLESTEROLHypercholesterolaemiaMetabolism and nutrition disorders2021-042021-04-01D
ONCO-EXONCO-EX-70100470100470160MWHITEYClinwrightinib 200 mgClinwrightinib 200 mg2022-03-181APPENDECTOMYAppendicectomySurgical and medical procedures2014-102014-10-01D
ONCO-EXONCO-EX-70100570100570162MWHITEYClinwrightinib 200 mgClinwrightinib 200 mg2022-03-311DEPRESSIONDepressionPsychiatric disorders2021-06-242021-06-24
ONCO-EXONCO-EX-70100570100570162MWHITEYClinwrightinib 200 mgClinwrightinib 200 mg2022-03-312HIGH CHOLESTEROLHypercholesterolaemiaMetabolism and nutrition disorders2011-122011-12-01D
ONCO-EXONCO-EX-70100570100570162MWHITEYClinwrightinib 200 mgClinwrightinib 200 mg2022-03-313HYPERTENSIONHypertensionVascular disorders2009-10-222009-10-22
ONCO-EXONCO-EX-70100570100570162MWHITEYClinwrightinib 200 mgClinwrightinib 200 mg2022-03-314INSOMNIAInsomniaPsychiatric disorders2005-01-042005-01-04
ONCO-EXONCO-EX-70100570100570162MWHITEYClinwrightinib 200 mgClinwrightinib 200 mg2022-03-315TYPE 2 DIABETESType 2 diabetes mellitusMetabolism and nutrition disorders2007-072007-07-01D
ONCO-EXONCO-EX-7010061HYPERTENSIONHypertensionVascular disorders2006-062006-06-01D
ONCO-EXONCO-EX-70100770100770163MWHITEYStandard of CareStandard of Care2022-04-191HYPERTENSIONHypertensionVascular disorders2011-052011-05-01D
ONCO-EXONCO-EX-70100870100870154MWHITEYClinwrightinib 200 mgClinwrightinib 200 mg2022-04-261HIGH CHOLESTEROLHypercholesterolaemiaMetabolism and nutrition disorders2005-012005-01-01D
ONCO-EXONCO-EX-70100870100870154MWHITEYClinwrightinib 200 mgClinwrightinib 200 mg2022-04-262HYPERTENSIONHypertensionVascular disorders2007-032007-03-01D
ONCO-EXONCO-EX-70100870100870154MWHITEYClinwrightinib 200 mgClinwrightinib 200 mg2022-04-263HYSTERECTOMYHysterectomySurgical and medical procedures2012-032012-03-01D
ONCO-EXONCO-EX-70100970100970158MBLACK OR AFRICAN AMERICANYClinwrightinib 200 mgClinwrightinib 200 mg2022-04-181INSOMNIAInsomniaPsychiatric disorders2020-01-292020-01-29
ONCO-EXONCO-EX-70101070101070164FWHITEYClinwrightinib 200 mgClinwrightinib 200 mg2022-06-101APPENDECTOMYAppendicectomySurgical and medical procedures2012-072012-07-01D
ONCO-EXONCO-EX-70101070101070164FWHITEYClinwrightinib 200 mgClinwrightinib 200 mg2022-06-102HYPERTENSIONHypertensionVascular disorders2015-122015-12-01D
ONCO-EXONCO-EX-70101070101070164FWHITEYClinwrightinib 200 mgClinwrightinib 200 mg2022-06-103INSOMNIAInsomniaPsychiatric disorders2017-102017-10-01D
ONCO-EXONCO-EX-70101170101170162MWHITEYClinwrightinib 200 mgClinwrightinib 200 mg2022-06-161HIGH CHOLESTEROLHypercholesterolaemiaMetabolism and nutrition disorders2014-082014-08-01D
ONCO-EXONCO-EX-70101170101170162MWHITEYClinwrightinib 200 mgClinwrightinib 200 mg2022-06-162OSTEOARTHRITISOsteoarthritisMusculoskeletal and connective tissue disorders2010-06-062010-06-06