Clinwright Public work of Clinwright examples · free Start free

ADNPIX

NPI-X Item Analysis Data

BASIC DATA STRUCTURE · one record per subject per parameter per analysis visit per analysis date · keys USUBJID, PARAMCD, AVISIT, ADT, QSSEQ

Variables

VariableLabelTypeLengthDerivation
STUDYIDStudy IdentifiertextPredecessor ADSL.STUDYID
SITEIDStudy Site IdentifiertextPredecessor ADSL.SITEID
SITEGR1Pooled Site Group 1textPredecessor ADSL.SITEGR1
USUBJIDUnique Subject IdentifiertextPredecessor QS.USUBJID
TRTSDTDate of First Exposure to Treatmentinteger8Predecessor ADSL.TRTSDT
TRTEDTDate of Last Exposure to Treatmentinteger8Predecessor ADSL.TRTEDT
TRTPPlanned TreatmenttextPredecessor ADSL.TRT01P
TRTPNPlanned Treatment (N)integer8Predecessor ADSL.TRT01PN
AGEAgeinteger8Predecessor ADSL.AGE
AGEGR1Pooled Age Group 1textPredecessor ADSL.AGEGR1
AGEGR1NPooled Age Group 1 (N)integer8Predecessor ADSL.AGEGR1N
RACERacetextPredecessor ADSL.RACE
RACENRace (N)integer8Predecessor ADSL.RACEN
SEXSextextPredecessor ADSL.SEX
ITTFLIntent-to-Treat Population FlagtextPredecessor ADSL.ITTFL
EFFFLEfficacy Population FlagtextPredecessor ADSL.EFFFL
COMP24FLCompleters of Week 24 Population FlagtextPredecessor ADSL.COMP24FL
AVISITAnalysis VisittextCharacter version of the visit.
AVISITNAnalysis Visit (N)integer8Using window method in SAP Page 10 to determine AVISITN value based on ADY.
ADYAnalysis Relative Dayinteger8ADY = ADT - TRTSDT + 1, if ADT>=TRTSDT. ADY = ADT - TRTSDT, if ADT<TRTSDT.
ADTAnalysis Dateinteger8SAS date from QS.QSDTC
VISITNUMVisit Numberfloat8Predecessor QS.VISITNUM
VISITVisit NametextPredecessor QS.VISIT
PARAMParametertextPredecessor QS.QSTEST
PARAMCDParameter CodetextPredecessor QS.QSTESTCD
PARAMNParameter (N)integer8Assigned Sponsor
PARAMTYPParameter TypetextAssigned Sponsor
AVALAnalysis Valueinteger8
BASEBaseline Valueinteger8QS.QSSTRESN when QS.QSBLFL=Y.
CHGChange from Baselineinteger8AVAL - BASE, for post baseline records.
PCHGPercent Change from Baselineinteger8100* (CHG/BASE), for post baseline records.
ABLFLBaseline Record FlagtextPredecessor QS.QSBLFL
ANL01FLAnalysis Flag 01textSet ANL01FL=Y based on SAP Page 10 analysis windows.
DTYPEDerivation TypetextAssigned Sponsor
AWRANGEAnalysis Window Valid Relative RangetextWindow range, specified in the SAP Page 10.
AWTARGETAnalysis Window Targetinteger8Target day within the window, specified in the SAP Page 10.
AWTDIFFAnalysis Window Diff from Targetinteger8Absolute difference between AWTARGET and ADY
AWLOAnalysis Window Beginning Timepointinteger8Start day of the window, specified in the SAP Page 10.
AWHIAnalysis Window Ending Timepointinteger8End day of the window, specified in the SAP Page 10.
AWUAnalysis Window UnittextAssigned as "DAYS".
QSSEQSequence Numberinteger8Predecessor QS.QSSEQ

Program adnpix.sas

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

/*==== 00-header ====*/
/*----------------------------------------------------------------------------
  Data set : ADNPIX (NPI-X Item Analysis Data)
  Reporting effort : CSR
  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 QS records of the parameters PARAMCD's codelist lists, with the subject's TRTSDT, TRTEDT, STUDYID, SITEID, SITEGR1, TRT01P, TRT01PN, AGE, AGEGR1, AGEGR1N, RACE, RACEN, SEX, ITTFL, EFFFL, COMP24FL from ADSL. */
proc sort data=sdtm.qs(keep=studyid usubjid qsseq qstestcd qstest qsstresn qsblfl visitnum visit qsdtc where=(qstestcd in ('NPITM01S', 'NPITM02S', 'NPITM03S', 'NPITM04S', 'NPITM05S', 'NPITM06S', 'NPITM07S', 'NPITM08S', 'NPITM09S', 'NPITM10S', 'NPITM11S', 'NPITM12S', 'NPTOT'))) out=work._ds; by usubjid; run;
proc sort data=adam.adsl(keep=usubjid trtsdt trtedt studyid siteid sitegr1 trt01p trt01pn age agegr1 agegr1n race racen sex ittfl efffl comp24fl) out=work._adsl; by usubjid; run;
data work._ds;
  merge work._ds(in=_in) work._adsl;
  by usubjid;
  if _in;
  length trtp $200;
  trtp = trt01p;
  trtpn = trt01pn;
  length param $200;
  select (upcase(qstestcd));
    when ('NPITM01S') param = 'NPI-X Item A (Delusion) Score';
    when ('NPITM02S') param = 'NPI-X Item B (Hallucination) Score';
    when ('NPITM03S') param = 'NPI-X Item C (Agitation/Agression) Score';
    when ('NPITM04S') param = 'NPI-X Item D (Depression/Dysphoria) Score';
    when ('NPITM05S') param = 'NPI-X Item E (Anxiety) Score';
    when ('NPITM06S') param = 'NPI-X Item F (Eupohoria/Elation) Score';
    when ('NPITM07S') param = 'NPI-X Item G (Apathy/Indifference) Score';
    when ('NPITM08S') param = 'NPI-X Item H (Disinhibition) Score';
    when ('NPITM09S') param = 'NPI-X Item I (Irritability/Lability) Score';
    when ('NPITM10S') param = 'NPI-X Item J (Aberrant Motor Behavior) Score';
    when ('NPITM11S') param = 'NPI-X Item K (Night-time Behavior) Score';
    when ('NPITM12S') param = 'NPI-X Item L (Appetite/Eating Change) Score';
    when ('NPTOT') param = 'NPI-X (9) Total Score';
    otherwise param = '';
  end;
  if param = '' then do;
  select (upcase(qstest));
    when ('NPI-X ITEM A (DELUSION) SCORE') param = 'NPI-X Item A (Delusion) Score';
    when ('NPI-X ITEM B (HALLUCINATION) SCORE') param = 'NPI-X Item B (Hallucination) Score';
    when ('NPI-X ITEM C (AGITATION/AGRESSION) SCORE') param = 'NPI-X Item C (Agitation/Agression) Score';
    when ('NPI-X ITEM D (DEPRESSION/DYSPHORIA) SCORE', 'NPI-X ITEM D (DEPRESSION/DYSPHORIA) SCOR') param = 'NPI-X Item D (Depression/Dysphoria) Score';
    when ('NPI-X ITEM E (ANXIETY) SCORE') param = 'NPI-X Item E (Anxiety) Score';
    when ('NPI-X ITEM F (EUPOHORIA/ELATION) SCORE') param = 'NPI-X Item F (Eupohoria/Elation) Score';
    when ('NPI-X ITEM G (APATHY/INDIFFERENCE) SCORE') param = 'NPI-X Item G (Apathy/Indifference) Score';
    when ('NPI-X ITEM H (DISINHIBITION) SCORE') param = 'NPI-X Item H (Disinhibition) Score';
    when ('NPI-X ITEM I (IRRITABILITY/LABILITY) SCORE', 'NPI-X ITEM I (IRRITABILITY/LABILITY) SCO') param = 'NPI-X Item I (Irritability/Lability) Score';
    when ('NPI-X ITEM J (ABERRANT MOTOR BEHAVIOR) SCORE', 'NPI-X ITEM J (ABERRANT MOTOR BEHAVIOR) S') param = 'NPI-X Item J (Aberrant Motor Behavior) Score';
    when ('NPI-X ITEM K (NIGHT-TIME BEHAVIOR) SCORE') param = 'NPI-X Item K (Night-time Behavior) Score';
    when ('NPI-X ITEM L (APPETITE/EATING CHANGE) SCORE', 'NPI-X ITEM L (APPETITE/EATING CHANGE) SC') param = 'NPI-X Item L (Appetite/Eating Change) Score';
    when ('NPI-X (9) TOTAL SCORE') param = 'NPI-X (9) Total Score';
    when ('MEAN NPI-X', 'MEAN NPI-X (9) TOTAL (WEEK 4 TO 24)') param = 'Mean NPI-X (9) Total (Week 4 to 24)';
    otherwise param = qstest;
  end;
  end;
  length paramcd $200;
  paramcd = qstestcd;
  aval = qsstresn;
  length ablfl $200;
  ablfl = qsblfl;
run;

/*==== 20-parameters ====*/
/* PARAMN: the code of PARAM. */
proc format;
  invalue paramn_ (upcase just)

    "NPI-X ITEM A (DELUSION) SCORE" = 1

    "NPI-X ITEM B (HALLUCINATION) SCORE" = 2

    "NPI-X ITEM C (AGITATION/AGRESSION) SCORE" = 3

    "NPI-X ITEM D (DEPRESSION/DYSPHORIA) SCORE" = 4

    "NPI-X ITEM E (ANXIETY) SCORE" = 5

    "NPI-X ITEM F (EUPOHORIA/ELATION) SCORE" = 6

    "NPI-X ITEM G (APATHY/INDIFFERENCE) SCORE" = 7

    "NPI-X ITEM H (DISINHIBITION) SCORE" = 8

    "NPI-X ITEM I (IRRITABILITY/LABILITY) SCORE" = 9

    "NPI-X ITEM J (ABERRANT MOTOR BEHAVIOR) SCORE" = 10

    "NPI-X ITEM K (NIGHT-TIME BEHAVIOR) SCORE" = 11

    "NPI-X ITEM L (APPETITE/EATING CHANGE) SCORE" = 12

    "NPI-X (9) TOTAL SCORE" = 13

    "MEAN NPI-X (9) TOTAL (WEEK 4 TO 24)" = 14

    other = .;
run;
data work._ds;
  set work._ds;
  if param ne '' then paramn = input(param, paramn_.);
run;

/*==== 25-derived-parameters ====*/
/* AVAL[NPTOTMN] (Mean NPI-X (9) Total (Week 4 to 24)): take the mean of AVAL when PARAMCD=NPTOT from week 4 to 24. -- to write. */

/*==== 30-timing ====*/
/* ADT: QS.QSDTC as a SAS date. */
data work._ds;
  set work._ds;
  length _dtc $10;
  _dtc = qsdtc; /* (its first 10 characters: SUBSTR would complain of a shorter variable) */
  if length(_dtc) = 10 then adt = input(_dtc, ?? yymmdd10.);

  format adt date9.;
  drop _dtc;
run;

/* ADY: day of ADT relative to TRTSDT; no day 0. */
data work._ds;
  set work._ds;
  if nmiss(adt, trtsdt) = 0 then ady = adt - trtsdt + (adt >= trtsdt);
run;

/*==== 40-visits ====*/
/* AVISIT: the analysis visit whose window holds ADY (Baseline <=1, Week 2 2-21, Week 4 22-35, Week 6 36-49, Week 8 50-70, Week 12 71-98, Week 16 99-126, Week 20 127-154, Week 24 155-175, Week 26 >175). */
data work._ds;
  set work._ds;
  length avisit $40 awrange $20 awu $4;
  if missing(ady) then call missing(avisit, avisitn);

  else if ady <= 1 then do;
    avisit = "Baseline"; avisitn = 0; awtarget = 1; awlo = .; awhi = 1; awrange = "<=1";
  end;

  else if 2 <= ady <= 21 then do;
    avisit = "Week 2"; avisitn = 2; awtarget = 14; awlo = 2; awhi = 21; awrange = "2-21";
  end;

  else if 22 <= ady <= 35 then do;
    avisit = "Week 4"; avisitn = 4; awtarget = 28; awlo = 22; awhi = 35; awrange = "22-35";
  end;

  else if 36 <= ady <= 49 then do;
    avisit = "Week 6"; avisitn = 6; awtarget = 42; awlo = 36; awhi = 49; awrange = "36-49";
  end;

  else if 50 <= ady <= 70 then do;
    avisit = "Week 8"; avisitn = 8; awtarget = 56; awlo = 50; awhi = 70; awrange = "50-70";
  end;

  else if 71 <= ady <= 98 then do;
    avisit = "Week 12"; avisitn = 12; awtarget = 84; awlo = 71; awhi = 98; awrange = "71-98";
  end;

  else if 99 <= ady <= 126 then do;
    avisit = "Week 16"; avisitn = 16; awtarget = 112; awlo = 99; awhi = 126; awrange = "99-126";
  end;

  else if 127 <= ady <= 154 then do;
    avisit = "Week 20"; avisitn = 20; awtarget = 140; awlo = 127; awhi = 154; awrange = "127-154";
  end;

  else if 155 <= ady <= 175 then do;
    avisit = "Week 24"; avisitn = 24; awtarget = 168; awlo = 155; awhi = 175; awrange = "155-175";
  end;

  else if 176 <= ady then do;
    avisit = "Week 26"; avisitn = 26; awtarget = 182; awlo = 176; awhi = .; awrange = ">175";
  end;

  if not missing(avisitn) then do;
    awtdiff = abs(ady - awtarget);
    awu = 'DAYS';
  end;
run;

/*==== 50-baseline ====*/
/* BASE: AVAL of the baseline record (ABLFL = 'Y'), per subject and PARAMCD. */
proc sort data=work._ds; by usubjid paramcd; run;
data work._base(keep=usubjid paramcd base);
  set work._ds(where=(ablfl = 'Y'));
  base = aval;
run;
data work._ds;
  merge work._ds work._base;
  by usubjid paramcd;
run;

/* The baseline record without an analysis visit (a screening value, the test not done on the day of the first dose): the Baseline analysis visit. */
data work._ds;
  set work._ds;
  if ablfl = 'Y' and missing(avisit) then do; avisit = 'Baseline'; avisitn = 0; _blvis = 1; end;
run;
/* (Then a record of the same subject and PARAMCD at the Baseline visit that is not the baseline, the day of the first dose without a value: no analysis visit.) */
proc sort data=work._ds; by usubjid paramcd descending _blvis; run;
data work._ds;
  set work._ds;
  by usubjid paramcd;
  retain _blmov;
  if first.paramcd then _blmov = (_blvis = 1);
  if _blmov and ablfl ne 'Y' and avisit = 'Baseline' then call missing(avisit, avisitn);
  drop _blvis _blmov;
run;

/* CHG: AVAL - BASE, after baseline only. */
data work._ds;
  set work._ds;
  if nmiss(aval, base) = 0 and ablfl ne 'Y' and adt > trtsdt then chg = aval - base;
run;

/* PCHG: 100 * CHG / BASE, where BASE is not 0. */
data work._ds;
  set work._ds;
  if not missing(chg) and base not in (., 0) then pchg = 100 * chg / base;
run;

/*==== 70-other ====*/
/* PARAMTYP (Parameter Type): Set to "DERIVED" -- to write. */

/* DTYPE: at each analysis visit after baseline (2, 4, 6, 8, 8.1, 9.1, 10.1, 11.1, 12, 16, 20, 24, 26, 103.5, 106, 301) without a value, the last value before it (DTYPE = LOCF),
   per subject and PARAMCD: the record carried forward, at the visit it fills. */
/* Each window's record: the one nearest its target day (the one analyzed), the earlier on a tie. */
proc sort data=work._ds(where=(avisitn in (2, 4, 6, 8, 8.1, 9.1, 10.1, 11.1, 12, 16, 20, 24, 26, 103.5, 106, 301) and not missing(aval))) out=work._obs;
  by usubjid paramcd avisitn awtdiff ady;
run;
data work._obs; set work._obs; by usubjid paramcd avisitn; if first.avisitn; run;
data work._grid;
  set work._obs(keep=usubjid paramcd);
  by usubjid paramcd;
  if first.paramcd;
  do avisitn = 2, 4, 6, 8, 8.1, 9.1, 10.1, 11.1, 12, 16, 20, 24, 26, 103.5, 106, 301; output; end;
run;
data work._missing;
  merge work._grid(in=_want) work._obs(in=_have keep=usubjid paramcd avisitn);
  by usubjid paramcd avisitn;
  if _want and not _have;
run;
proc sql;
  create table work._locf as
  select o.*, m.avisitn as _to
  from work._missing as m, work._obs as o
  where o.usubjid = m.usubjid and o.paramcd = m.paramcd and o.avisitn < m.avisitn
  order by o.usubjid, o.paramcd, _to, o.avisitn;
quit;
data work._locf;
  set work._locf;
  by usubjid paramcd _to;
  if last._to;
  avisitn = _to;
  length dtype $8;
  dtype = 'LOCF';
  drop _to;
run;
/* The visit's name and window, as the observed records have it. */
proc sort data=work._obs(keep=avisitn avisit awtarget awlo awhi awrange) out=work._avisit nodupkey; by avisitn; run;
proc sort data=work._locf; by avisitn; run;
data work._locf;
  merge work._locf(in=_in drop=avisit awtarget awlo awhi awrange) work._avisit;
  by avisitn;
  if _in;
  awtdiff = abs(ady - awtarget);
run;
data work._ds; set work._ds work._locf; run;

/* ANL01FL: in each window of USUBJID, PARAMCD and AVISITN, the record nearest the target day (the earlier on a tie). */
proc sort data=work._ds;
  by usubjid paramcd avisitn awtdiff ady;
run;
data work._ds;
  set work._ds;
  by usubjid paramcd avisitn;
  length anl01fl $1;
  if not missing(avisitn) and first.avisitn then anl01fl = 'Y';
  else anl01fl = '';
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; %let _len15 = 1; %let _len16 = 1; %let _len17 = 1; %let _len18 = 1; %let _len19 = 1; %let _len20 = 1; %let _len21 = 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, 'SITEID') > 0 then do; _ren = catx(' ', _ren, 'SITEID=_rz2'); _asg = catx(' ', _asg, 'SITEID = _rz2;');
    _siz = catx(' ', _siz, '_len2 = max(_len2, lengthn(SITEID));'); end;
  if varnum(_dsid, 'SITEGR1') > 0 then do; _ren = catx(' ', _ren, 'SITEGR1=_rz3'); _asg = catx(' ', _asg, 'SITEGR1 = _rz3;');
    _siz = catx(' ', _siz, '_len3 = max(_len3, lengthn(SITEGR1));'); end;
  if varnum(_dsid, 'USUBJID') > 0 then do; _ren = catx(' ', _ren, 'USUBJID=_rz4'); _asg = catx(' ', _asg, 'USUBJID = _rz4;');
    _siz = catx(' ', _siz, '_len4 = max(_len4, lengthn(USUBJID));'); end;
  if varnum(_dsid, 'TRTP') > 0 then do; _ren = catx(' ', _ren, 'TRTP=_rz5'); _asg = catx(' ', _asg, 'TRTP = _rz5;');
    _siz = catx(' ', _siz, '_len5 = max(_len5, lengthn(TRTP));'); end;
  if varnum(_dsid, 'AGEGR1') > 0 then do; _ren = catx(' ', _ren, 'AGEGR1=_rz6'); _asg = catx(' ', _asg, 'AGEGR1 = _rz6;');
    _siz = catx(' ', _siz, '_len6 = max(_len6, lengthn(AGEGR1));'); end;
  if varnum(_dsid, 'RACE') > 0 then do; _ren = catx(' ', _ren, 'RACE=_rz7'); _asg = catx(' ', _asg, 'RACE = _rz7;');
    _siz = catx(' ', _siz, '_len7 = max(_len7, lengthn(RACE));'); end;
  if varnum(_dsid, 'SEX') > 0 then do; _ren = catx(' ', _ren, 'SEX=_rz8'); _asg = catx(' ', _asg, 'SEX = _rz8;');
    _siz = catx(' ', _siz, '_len8 = max(_len8, lengthn(SEX));'); end;
  if varnum(_dsid, 'ITTFL') > 0 then do; _ren = catx(' ', _ren, 'ITTFL=_rz9'); _asg = catx(' ', _asg, 'ITTFL = _rz9;');
    _siz = catx(' ', _siz, '_len9 = max(_len9, lengthn(ITTFL));'); end;
  if varnum(_dsid, 'EFFFL') > 0 then do; _ren = catx(' ', _ren, 'EFFFL=_rz10'); _asg = catx(' ', _asg, 'EFFFL = _rz10;');
    _siz = catx(' ', _siz, '_len10 = max(_len10, lengthn(EFFFL));'); end;
  if varnum(_dsid, 'COMP24FL') > 0 then do; _ren = catx(' ', _ren, 'COMP24FL=_rz11'); _asg = catx(' ', _asg, 'COMP24FL = _rz11;');
    _siz = catx(' ', _siz, '_len11 = max(_len11, lengthn(COMP24FL));'); end;
  if varnum(_dsid, 'AVISIT') > 0 then do; _ren = catx(' ', _ren, 'AVISIT=_rz12'); _asg = catx(' ', _asg, 'AVISIT = _rz12;');
    _siz = catx(' ', _siz, '_len12 = max(_len12, lengthn(AVISIT));'); end;
  if varnum(_dsid, 'VISIT') > 0 then do; _ren = catx(' ', _ren, 'VISIT=_rz13'); _asg = catx(' ', _asg, 'VISIT = _rz13;');
    _siz = catx(' ', _siz, '_len13 = max(_len13, lengthn(VISIT));'); end;
  if varnum(_dsid, 'PARAM') > 0 then do; _ren = catx(' ', _ren, 'PARAM=_rz14'); _asg = catx(' ', _asg, 'PARAM = _rz14;');
    _siz = catx(' ', _siz, '_len14 = max(_len14, lengthn(PARAM));'); end;
  if varnum(_dsid, 'PARAMCD') > 0 then do; _ren = catx(' ', _ren, 'PARAMCD=_rz15'); _asg = catx(' ', _asg, 'PARAMCD = _rz15;');
    _siz = catx(' ', _siz, '_len15 = max(_len15, lengthn(PARAMCD));'); end;
  if varnum(_dsid, 'PARAMTYP') > 0 then do; _ren = catx(' ', _ren, 'PARAMTYP=_rz16'); _asg = catx(' ', _asg, 'PARAMTYP = _rz16;');
    _siz = catx(' ', _siz, '_len16 = max(_len16, lengthn(PARAMTYP));'); end;
  if varnum(_dsid, 'ABLFL') > 0 then do; _ren = catx(' ', _ren, 'ABLFL=_rz17'); _asg = catx(' ', _asg, 'ABLFL = _rz17;');
    _siz = catx(' ', _siz, '_len17 = max(_len17, lengthn(ABLFL));'); end;
  if varnum(_dsid, 'ANL01FL') > 0 then do; _ren = catx(' ', _ren, 'ANL01FL=_rz18'); _asg = catx(' ', _asg, 'ANL01FL = _rz18;');
    _siz = catx(' ', _siz, '_len18 = max(_len18, lengthn(ANL01FL));'); end;
  if varnum(_dsid, 'DTYPE') > 0 then do; _ren = catx(' ', _ren, 'DTYPE=_rz19'); _asg = catx(' ', _asg, 'DTYPE = _rz19;');
    _siz = catx(' ', _siz, '_len19 = max(_len19, lengthn(DTYPE));'); end;
  if varnum(_dsid, 'AWRANGE') > 0 then do; _ren = catx(' ', _ren, 'AWRANGE=_rz20'); _asg = catx(' ', _asg, 'AWRANGE = _rz20;');
    _siz = catx(' ', _siz, '_len20 = max(_len20, lengthn(AWRANGE));'); end;
  if varnum(_dsid, 'AWU') > 0 then do; _ren = catx(' ', _ren, 'AWU=_rz21'); _asg = catx(' ', _asg, 'AWU = _rz21;');
    _siz = catx(' ', _siz, '_len21 = max(_len21, lengthn(AWU));'); 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 _len15 1 _len16 1 _len17 1 _len18 1 _len19 1 _len20 1 _len21 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);
    call symputx('_len15', _len15);
    call symputx('_len16', _len16);
    call symputx('_len17', _len17);
    call symputx('_len18', _len18);
    call symputx('_len19', _len19);
    call symputx('_len20', _len20);
    call symputx('_len21', _len21);
  end;
run;
data adam.adnpix(label="NPI-X Item Analysis Data");
  attrib
    STUDYID  length=$&_len1 label="Study Identifier"
    SITEID   length=$&_len2 label="Study Site Identifier"
    SITEGR1  length=$&_len3 label="Pooled Site Group 1"
    USUBJID  length=$&_len4 label="Unique Subject Identifier"
    TRTSDT   length=8 label="Date of First Exposure to Treatment" format=DATE9.
    TRTEDT   length=8 label="Date of Last Exposure to Treatment" format=DATE9.
    TRTP     length=$&_len5 label="Planned Treatment"
    TRTPN    length=8 label="Planned Treatment (N)"
    AGE      length=8 label="Age"
    AGEGR1   length=$&_len6 label="Pooled Age Group 1"
    AGEGR1N  length=8 label="Pooled Age Group 1 (N)"
    RACE     length=$&_len7 label="Race"
    RACEN    length=8 label="Race (N)"
    SEX      length=$&_len8 label="Sex"
    ITTFL    length=$&_len9 label="Intent-to-Treat Population Flag"
    EFFFL    length=$&_len10 label="Efficacy Population Flag"
    COMP24FL length=$&_len11 label="Completers of Week 24 Population Flag"
    AVISIT   length=$&_len12 label="Analysis Visit"
    AVISITN  length=8 label="Analysis Visit (N)"
    ADY      length=8 label="Analysis Relative Day"
    ADT      length=8 label="Analysis Date" format=DATE9.
    VISITNUM length=8 label="Visit Number"
    VISIT    length=$&_len13 label="Visit Name"
    PARAM    length=$&_len14 label="Parameter"
    PARAMCD  length=$&_len15 label="Parameter Code"
    PARAMN   length=8 label="Parameter (N)"
    PARAMTYP length=$&_len16 label="Parameter Type"
    AVAL     length=8 label="Analysis Value"
    BASE     length=8 label="Baseline Value"
    CHG      length=8 label="Change from Baseline"
    PCHG     length=8 label="Percent Change from Baseline"
    ABLFL    length=$&_len17 label="Baseline Record Flag"
    ANL01FL  length=$&_len18 label="Analysis Flag 01"
    DTYPE    length=$&_len19 label="Derivation Type"
    AWRANGE  length=$&_len20 label="Analysis Window Valid Relative Range"
    AWTARGET length=8 label="Analysis Window Target"
    AWTDIFF  length=8 label="Analysis Window Diff from Target"
    AWLO     length=8 label="Analysis Window Beginning Timepoint"
    AWHI     length=8 label="Analysis Window Ending Timepoint"
    AWU      length=$&_len21 label="Analysis Window Unit"
    QSSEQ    length=8 label="Sequence Number"
  ;
  set work._final&_ren;
  &_asg
  if not missing(VISITNUM) then VISITNUM = round(VISITNUM, 1e-1);
  keep STUDYID SITEID SITEGR1 USUBJID TRTSDT TRTEDT TRTP TRTPN AGE AGEGR1 AGEGR1N RACE RACEN SEX ITTFL EFFFL COMP24FL AVISIT AVISITN ADY ADT VISITNUM VISIT PARAM PARAMCD PARAMN PARAMTYP AVAL BASE CHG PCHG ABLFL ANL01FL DTYPE AWRANGE AWTARGET AWTDIFF AWLO AWHI AWU QSSEQ;
run;
proc sort data=adam.adnpix; by USUBJID PARAMCD AVISIT ADT QSSEQ; run;

Data (first 20 of 61,939 records, uploaded)

STUDYIDSITEIDSITEGR1USUBJIDTRTSDTTRTEDTTRTPTRTPNAGEAGEGR1AGEGR1NRACERACENSEXITTFLEFFFLCOMP24FLAVISITAVISITNADYADTVISITNUMVISITPARAMPARAMCDPARAMNPARAMTYPAVALBASECHGPCHGABLFLANL01FLDTYPEAWRANGEAWTARGETAWTDIFFAWLOAWHIAWUQSSEQ
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYY8.1632014-03-058WEEK 8NPI-X Item A (Delusion) ScoreNPITM01S1000YLOCFDAYS3102
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYY9.1632014-03-058WEEK 8NPI-X Item A (Delusion) ScoreNPITM01S1000YLOCFDAYS3102
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYY10.1632014-03-058WEEK 8NPI-X Item A (Delusion) ScoreNPITM01S1000YLOCFDAYS3102
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYY11.1632014-03-058WEEK 8NPI-X Item A (Delusion) ScoreNPITM01S1000YLOCFDAYS3102
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYY103.51822014-07-0213WEEK 26NPI-X Item A (Delusion) ScoreNPITM01S1000YLOCFDAYS3277
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYY1061822014-07-0213WEEK 26NPI-X Item A (Delusion) ScoreNPITM01S1000YLOCFDAYS3277
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYY3011822014-07-0213WEEK 26NPI-X Item A (Delusion) ScoreNPITM01S1000YLOCFDAYS3277
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYYBaseline012014-01-023BASELINENPI-X Item A (Delusion) ScoreNPITM01S100YY<=1101DAYS3002
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYYWeek 1212842014-03-269WEEK 12NPI-X Item A (Delusion) ScoreNPITM01S1000Y71-988407198DAYS3127
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYYWeek 1212982014-04-099.1WEEK 14 (T)NPI-X Item A (Delusion) ScoreNPITM01S100071-9884147198DAYS3152
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYYWeek 16161262014-05-0710WEEK 16NPI-X Item A (Delusion) ScoreNPITM01S1000Y99-1261121499126DAYS3177
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYYWeek 22152014-01-164WEEK 2NPI-X Item A (Delusion) ScoreNPITM01S1000Y2-21141221DAYS3027
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYYWeek 20201402014-05-2111WEEK 20NPI-X Item A (Delusion) ScoreNPITM01S1000Y127-1541400127154DAYS3202
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYYWeek 20201542014-06-0411.1WEEK 22 (T)NPI-X Item A (Delusion) ScoreNPITM01S1000127-15414014127154DAYS3227
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYYWeek 24241682014-06-1812WEEK 24NPI-X Item A (Delusion) ScoreNPITM01S1000Y155-1751680155175DAYS3252
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYYWeek 26261822014-07-0213WEEK 26NPI-X Item A (Delusion) ScoreNPITM01S1000Y>1751820176DAYS3277
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYYWeek 44292014-01-305WEEK 4NPI-X Item A (Delusion) ScoreNPITM01S1000Y22-352812235DAYS3052
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYYWeek 66422014-02-127WEEK 6NPI-X Item A (Delusion) ScoreNPITM01S1000Y36-494203649DAYS3077
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYYWeek 88632014-03-058WEEK 8NPI-X Item A (Delusion) ScoreNPITM01S1000Y50-705675070DAYS3102
CDISCPILOT0170170101-701-10152014-01-022014-07-02Placebo063<651WHITE1FYYY8.1632014-03-058WEEK 8NPI-X Item B (Hallucination) ScoreNPITM02S2000YLOCFDAYS3104