A leading global CRO 1 Effective Use of the RETAIN Statement in Programming Clinical Trial Mingxia Chen Biostatistician Beijing, China
A leading global CRO 2 Introduction RETAIN statement causes a variable that is created by an INPUT or assignment statement to retain its value from one iteration of the DATA step to the next ---- SAS help document In contrast to the default DATA step behavior, without RETAIN statement, SAS automatically sets new variables in the data step to missing at the start of each iterationmissing The RETAIN statement is very useful to perform data manipulation across observations. RETAIN is simpler and more flexible, to speed up your program.
A leading global CRO 3 Example 1 Concatenate character values from multiple records of the same variable
A leading global CRO 4 Original Dataset (SUPPEX) Result Dataset (REASON) USUBJIDIDVARIDVARVALQNAMQLABELQVAL EXSEQ1 EXLOT 1 Lot Number EXSEQ1 EXLOT 2 Lot Number EXSEQ1 EXLOT 3 Lot Number EXSEQ2IIREAS Reason for injection interruption Adverse Event EXSEQ2IISPECSpecify for interruption ALLERGIC REACTION, SKIN RASH, DYSPNEA EXSEQ2 EXLOT 1 Lot Number EXSEQ2 EXLOT 2 Lot Number …… …… USUBJIDEXSEQEXLOTREASON , , Adverse Event: ALLERGIC REACTION, SKIN RASH, DYSPNEA , …… ……
A leading global CRO 5 Original Dataset (SUPPEX) Result Dataset (RSLTDS) EXSEQ 2 IIREAS Reason for injection interruption Adverse Event EXSEQ 2 IISPEC Specify for interruption ALLERGIC REACTION, SKIN RASH, DYSPNEA USUBJIDIDVAR IDVARV AL QNAMQLABELQVAL EXSE Q 1 EXLOT 1 Lot Number EXSE Q 1 EXLOT 2 Lot Number EXSE Q 1 EXLOT 3 Lot Number EXSE Q 2 EXLOT 1 Lot Number EXSE Q 2 EXLOT 2 Lot Number …… …… USUBJIDEXSEQEXLOTREASON , , , …… ……
A leading global CRO 6 PROC SORT DATA=SUPPEX; BY USUBJID IDVAR IDVARVAL QNAM; RUN; DATA RSLTDS(KEEP=USUBJID EXSEQ EXLOT REASON); SET SUPPEX; BY USUBJID IDVAR IDVARVAL QNAM; FORMAT EXLOT REASON $200.; RETAIN EXLOT REASON; IF FIRST.IDVARVAL THEN DO; EXLOT=""; REASON =""; END; IF INDEX(QNAM,“EXLOT")>0 THEN EXLOT=CATX(“, ", OF EXLOT QVAL); IF QNAM IN (“IIREAS", “IISPEC") THEN REASON=CATX(": ", OF REASON QVAL); IF LAST.IDVARVAL; EXSEQ=INPUT(IDVARVAL, best.); RUN; SAS Code Assigns initial value (missing) to EXLOT, REASON Prevents the 2 variables from being reset to missing for each iteration. Concatenates character values of QVAL in multiple records Keeps the last observation per SUBJECT per EXSEQ
A leading global CRO 7 Example 2 Select the previous minimum sum of longest diameters in oncology clinical trials
A leading global CRO 8 Original dataset (TR) USUBJIDVISITNUMVISITTRTESTCDTRTEST TRSTRES N TRSTRES U PRE-TREATMENTSUMLDIAM SUM OF LONGEST DIAMETER 74mm PRE-TREATMENTSUMLDIAM SUM OF LONGEST DIAMETER 94mm TUMOR ASSESSMENT 1 SUMLDIAM SUM OF LONGEST DIAMETER 84mm TUMOR ASSESSMENT 2 SUMLDIAM SUM OF LONGEST DIAMETER 92mm TUMOR ASSESSMENT 3 SUMLDIAM SUM OF LONGEST DIAMETER 106mm PRE-TREATMENTSUMLDIAM SUM OF LONGEST DIAMETER 96mm TUMOR ASSESSMENT 1 SUMLDIAM SUM OF LONGEST DIAMETER 100mm TUMOR ASSESSMENT 3 SUMLDIAM SUM OF LONGEST DIAMETER 95mm PRE-TREATMENTSUMLDIAM SUM OF LONGEST DIAMETER 188mm TUMOR ASSESSMENT 1 SUMLDIAM SUM OF LONGEST DIAMETER 65mm TUMOR ASSESSMENT 2 SUMLDIAM SUM OF LONGEST DIAMETER 66mm TUMOR ASSESSMENT 3 SUMLDIAM SUM OF LONGEST DIAMETER 66mm TUMOR ASSESSMENT 4 SUMLDIAM SUM OF LONGEST DIAMETER 63mm TUMOR ASSESSMENT 5 SUMLDIAM SUM OF LONGEST DIAMETER 61mm …… ……
A leading global CRO 9 Result Dataset (PREMINSL) USUBJID VISITNU M VISIT TRTESTC D TRTEST TRSTRES N TRSTRES U PREMIN SL PRE-TREATMENT SUMLDIA M SUM OF LONGEST DIAMETER 74mm PRE-TREATMENT SUMLDIA M SUM OF LONGEST DIAMETER 94mm TUMOR ASSESSMENT 1 SUMLDIA M SUM OF LONGEST DIAMETER 84mm TUMOR ASSESSMENT 2 SUMLDIA M SUM OF LONGEST DIAMETER 92mm TUMOR ASSESSMENT 3 SUMLDIA M SUM OF LONGEST DIAMETER 106mm PRE-TREATMENT SUMLDIA M SUM OF LONGEST DIAMETER 96mm TUMOR ASSESSMENT 1 SUMLDIA M SUM OF LONGEST DIAMETER 100mm TUMOR ASSESSMENT 3 SUMLDIA M SUM OF LONGEST DIAMETER 95mm PRE-TREATMENT SUMLDIA M SUM OF LONGEST DIAMETER 188mm TUMOR ASSESSMENT 1 SUMLDIA M SUM OF LONGEST DIAMETER 65mm TUMOR ASSESSMENT 2 SUMLDIA M SUM OF LONGEST DIAMETER 66mm TUMOR ASSESSMENT 3 SUMLDIA M SUM OF LONGEST DIAMETER 66mm TUMOR ASSESSMENT 4 SUMLDIA M SUM OF LONGEST DIAMETER 63mm TUMOR ASSESSMENT 5 SUMLDIA M SUM OF LONGEST DIAMETER 61mm63 …… ……
A leading global CRO 10 SAS Code PROC SORT DATA=TR; BY USUBJID TRTESTCD VISITNUM; RUN; DATA PREMINSL(DROP=LASTSL); SET TR; BY USUBJID TRTESTCD VISITNUM; RETAIN PREMINSL ; LASTSL=LAG(TRSTRESN); IF FIRST.TRTESTCD THEN DO; LASTSL=.; PREMINSL=.; END; ELSE PREMINSL=MIN(PREMINSL, LASTSL); RUN; Prevents PREMINSL from being reset to missing for each iterationSets LASTSL to missing for the first visit of each SUBJECTLAG function to Get the value of the last observationSets PREMINSL to missing for the first visit of each SUBJECT Compares PREMINSL to LASTSL in current iteration and resets value if LASTSL is smaller
A leading global CRO 11 Example 3 Count the number of observations (example AE table summary)
A leading global CRO 12 AE Summary Table
A leading global CRO 13 Analysis Dataset (ADAE) TRTANUSUBJIDAESEQAETERMTEAEFLTESAEFLRTEAEFL A CHEILITIS A CONSTIPATIONY A CONSTIPATIONY A CONSTIPATIONY A DIARRHEAY A BACK PAIN (THORACAL)Y Y B ANEMIAY B FEVER WITH CHILLSY B NAUSEAY B PNEUMONIAY Y B ASYMPTOMATIC PULMONAL EMBOLE B LOSS OF APPETITEY Y B NAUSEAY B NEUTROPENIAY B NEUTROPENIAY B PAIN LEFT ILIAC REGION (OS ILIUM) B PAIN RIGHT CALFY Y B WEAKNESSY Y
A leading global CRO 14 SQL Procedure
A leading global CRO 15 Result Dataset (AECNT)
A leading global CRO 16 SAS Code PROC SORT DATA=ADAE; BY TRTAN USUBJID AESEQ; RUN; DATA AECNT(KEEP=TRTAN COL1 COLU1 SUBJCNT EVECNT); SET ADAE; BY TRTAN USUBJID AESEQ; ARRAY AEFL{3} $ TEAEFL RTEAEFL TESAEFL; ARRAY SUBJAE{3} SUBJAE1-SUBJAE3; ARRAY SCNT{3} SCNT1-SCNT3; ARRAY AECNT {3} AECNT1-AECNT3; RETAIN SCNT1-SCNT3 AECNT1-AECNT3 0; IF FIRST.TRTAN THEN DO I=1 TO hbound(SCNT) ; SCNT{I}=0; AECNT{I}=0; END; IF FIRST.USUBJID THEN DO I=1 TO hbound(SUBJAE) ; SUBJAE{I}=0; END; DO I=1 TO hbound(SUBJAE) ; IF AEFL{I}='Y' THEN SUBJAE{I}+1; END; IF LAST.USUBJID THEN DO I=1 TO hbound(SCNT) ; IF SUBJAE{I}>=1 THEN SCNT{I}=SCNT{I}+1; AECNT{I}=AECNT{I}+SUBJAE{I}; END; IF LAST.TRTAN THEN DO I=1 TO hbound(SCNT) ; COL1=I; COLU1=PUT(COL1, COL1F.); SUBJCNT=SCNT{I}; EVECNT=AECNT{I}; OUTPUT; END; RUN; Assigns the 0 for each treatment groupAssigns the initial value (0) of each AE category for each subject Count the number of AEs per SUBJECT for each AE category. Count Number of subject (SCNT{i}) and Number of AEs (AECNT{i} per AE category. Assigns the initial value (0) for the 6 variables Output the Number of subject and Number or events for each category.
A leading global CRO 17 Conclusion The RETAIN statement can carry over values from one observation to next, so it is very useful to manipulate the data across observations.
A leading global CRO 18 Q&A Thanks