Download presentation
Presentation is loading. Please wait.
Published byGarry Bond Modified over 8 years ago
1
A leading global CRO 1 Effective Use of the RETAIN Statement in Programming Clinical Trial Mingxia Chen Biostatistician Beijing, China
2
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.
3
A leading global CRO 3 Example 1 Concatenate character values from multiple records of the same variable
4
A leading global CRO 4 Original Dataset (SUPPEX) Result Dataset (REASON) USUBJIDIDVARIDVARVALQNAMQLABELQVAL 100-5001EXSEQ1 EXLOT 1 Lot Number 1583918 100-5001EXSEQ1 EXLOT 2 Lot Number 2590118 100-5001EXSEQ1 EXLOT 3 Lot Number 3598303 100-5001EXSEQ2IIREAS Reason for injection interruption Adverse Event 100-5001EXSEQ2IISPECSpecify for interruption ALLERGIC REACTION, SKIN RASH, DYSPNEA 100-5002EXSEQ2 EXLOT 1 Lot Number 1540327 100-5002EXSEQ2 EXLOT 2 Lot Number 2558160 …… …… USUBJIDEXSEQEXLOTREASON 100-50011583918, 590118, 598303 100-50012 Adverse Event: ALLERGIC REACTION, SKIN RASH, DYSPNEA 100-50022540327, 558160 …… ……
5
A leading global CRO 5 Original Dataset (SUPPEX) Result Dataset (RSLTDS) 100-5001 EXSEQ 2 IIREAS Reason for injection interruption Adverse Event 100-5001 EXSEQ 2 IISPEC Specify for interruption ALLERGIC REACTION, SKIN RASH, DYSPNEA USUBJIDIDVAR IDVARV AL QNAMQLABELQVAL 100-5001 EXSE Q 1 EXLOT 1 Lot Number 1583918 100-5001 EXSE Q 1 EXLOT 2 Lot Number 2590118 100-5001 EXSE Q 1 EXLOT 3 Lot Number 3598303 100-5002 EXSE Q 2 EXLOT 1 Lot Number 1540327 100-5002 EXSE Q 2 EXLOT 2 Lot Number 2558160 …… …… USUBJIDEXSEQEXLOTREASON 100-50011583918, 590118, 598303 100-50022540327, 558160 …… ……
6
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
7
A leading global CRO 7 Example 2 Select the previous minimum sum of longest diameters in oncology clinical trials
8
A leading global CRO 8 Original dataset (TR) USUBJIDVISITNUMVISITTRTESTCDTRTEST TRSTRES N TRSTRES U 100-5001PRE-TREATMENTSUMLDIAM SUM OF LONGEST DIAMETER 74mm 100-5002PRE-TREATMENTSUMLDIAM SUM OF LONGEST DIAMETER 94mm 100-5002110 TUMOR ASSESSMENT 1 SUMLDIAM SUM OF LONGEST DIAMETER 84mm 100-5002120 TUMOR ASSESSMENT 2 SUMLDIAM SUM OF LONGEST DIAMETER 92mm 100-5002130 TUMOR ASSESSMENT 3 SUMLDIAM SUM OF LONGEST DIAMETER 106mm 100-5005PRE-TREATMENTSUMLDIAM SUM OF LONGEST DIAMETER 96mm 100-5005110 TUMOR ASSESSMENT 1 SUMLDIAM SUM OF LONGEST DIAMETER 100mm 100-5005130 TUMOR ASSESSMENT 3 SUMLDIAM SUM OF LONGEST DIAMETER 95mm 101-5002PRE-TREATMENTSUMLDIAM SUM OF LONGEST DIAMETER 188mm 101-5002110 TUMOR ASSESSMENT 1 SUMLDIAM SUM OF LONGEST DIAMETER 65mm 101-5002120 TUMOR ASSESSMENT 2 SUMLDIAM SUM OF LONGEST DIAMETER 66mm 101-5002130 TUMOR ASSESSMENT 3 SUMLDIAM SUM OF LONGEST DIAMETER 66mm 101-5002140 TUMOR ASSESSMENT 4 SUMLDIAM SUM OF LONGEST DIAMETER 63mm 101-5002150 TUMOR ASSESSMENT 5 SUMLDIAM SUM OF LONGEST DIAMETER 61mm …… ……
9
A leading global CRO 9 Result Dataset (PREMINSL) USUBJID VISITNU M VISIT TRTESTC D TRTEST TRSTRES N TRSTRES U PREMIN SL 100-5001PRE-TREATMENT SUMLDIA M SUM OF LONGEST DIAMETER 74mm. 100-5002PRE-TREATMENT SUMLDIA M SUM OF LONGEST DIAMETER 94mm. 100-5002110 TUMOR ASSESSMENT 1 SUMLDIA M SUM OF LONGEST DIAMETER 84mm94 100-5002120 TUMOR ASSESSMENT 2 SUMLDIA M SUM OF LONGEST DIAMETER 92mm84 100-5002130 TUMOR ASSESSMENT 3 SUMLDIA M SUM OF LONGEST DIAMETER 106mm84 100-5005PRE-TREATMENT SUMLDIA M SUM OF LONGEST DIAMETER 96mm. 100-5005110 TUMOR ASSESSMENT 1 SUMLDIA M SUM OF LONGEST DIAMETER 100mm96 100-5005130 TUMOR ASSESSMENT 3 SUMLDIA M SUM OF LONGEST DIAMETER 95mm96 101-5002PRE-TREATMENT SUMLDIA M SUM OF LONGEST DIAMETER 188mm. 101-5002110 TUMOR ASSESSMENT 1 SUMLDIA M SUM OF LONGEST DIAMETER 65mm188 101-5002120 TUMOR ASSESSMENT 2 SUMLDIA M SUM OF LONGEST DIAMETER 66mm65 101-5002130 TUMOR ASSESSMENT 3 SUMLDIA M SUM OF LONGEST DIAMETER 66mm65 101-5002140 TUMOR ASSESSMENT 4 SUMLDIA M SUM OF LONGEST DIAMETER 63mm65 101-5002150 TUMOR ASSESSMENT 5 SUMLDIA M SUM OF LONGEST DIAMETER 61mm63 …… ……
10
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
11
A leading global CRO 11 Example 3 Count the number of observations (example AE table summary)
12
A leading global CRO 12 AE Summary Table
13
A leading global CRO 13 Analysis Dataset (ADAE) TRTANUSUBJIDAESEQAETERMTEAEFLTESAEFLRTEAEFL A100-50011CHEILITIS A100-50012CONSTIPATIONY A100-50013CONSTIPATIONY A100-50014CONSTIPATIONY A100-50015DIARRHEAY A100-50041BACK PAIN (THORACAL)Y Y B100-50021ANEMIAY B100-50031FEVER WITH CHILLSY B100-50032NAUSEAY B100-50033PNEUMONIAY Y B100-50051ASYMPTOMATIC PULMONAL EMBOLE B100-50052LOSS OF APPETITEY Y B100-50053NAUSEAY B100-50054NEUTROPENIAY B100-50055NEUTROPENIAY B100-50056PAIN LEFT ILIAC REGION (OS ILIUM) B100-50057PAIN RIGHT CALFY Y B100-50058WEAKNESSY Y
14
A leading global CRO 14 SQL Procedure
15
A leading global CRO 15 Result Dataset (AECNT)
16
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.
17
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.
18
A leading global CRO 18 Q&A Thanks
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.