Last Observation Carried Forward
Section content first added by: Daniel Boisvert
DATA lab;
INPUT usubjid $ lbtestcd $ avisitn aval;
DATALINES;
101-1001 WBC 0 10
101-1001 WBC 1 20
101-1001 WBC 2 30
101-1001 WBC 3 .
101-1001 WBC 4 .
101-1001 RBC 0 100
101-1001 RBC 1 200
101-1001 RBC 2 300
101-1001 RBC 3 .
101-1001 RBC 4 400
;
RUN;
PROC SORT DATA=lab;
BY usubjid lbtestcd avisitn;
RUN;
************************************************;
**** When using RETAIN be absolutely sure ****;
**** not to drag records between patients ****;
**** or testcds. ****;
**** ****;
**** In this example keep aval and avallocf ****;
**** separate to show what is going on. ****;
**** Generally, aval would be overwritten ****;
**** with the LOCFed values. ****;
************************************************;
DATA locf;
LENGTH dtype $15;
RETAIN retaval;
SET lab;
BY usubjid lbtestcd avisitn;
IF FIRST.lbtestcd THEN retaval=.;
IF aval NE . THEN retaval=aval;
IF aval=. THEN DO;
avallocf=retaval;
dtype='LOCF';
END;
ELSE avallocf=aval;
LABEL dtype = 'Derivation Type';
RUN;