## Imputing next visit using LOCF

Solved
Super Contributor
Posts: 301

# Imputing next visit using LOCF

Hi everyone, I need to imputed the next VISIT record (only the next one) using LOCF when the AE stop, i.e

VISIT 01DEC2008 for subject1 and VISIT 30JAN2009 for subject 2, tha at the moment are missing.

data have;

informat VISIT date9. START date9. STOP date9.;

input SUBJID  VISIT START STOP;

format VISIT date9. START date9. STOP date9.;

cards;

1 02APR2008  07NOV2008 26NOV2008

1 07APR2008  07NOV2008 26NOV2008

1 12MAY2008  07NOV2008 26NOV2008

1 19MAY2008  07NOV2008 26NOV2008

1 30JUN2008  07NOV2008 26NOV2008

1 01JUL2008  07NOV2008 26NOV2008

1 07JUL2008  07NOV2008 26NOV2008

1 07AUG2008  07NOV2008 26NOV2008

1 29SEP2008  07NOV2008 26NOV2008

1 13OCT2008  07NOV2008 26NOV2008

1 20OCT2008  07NOV2008 26NOV2008

1 01DEC2008      .        .

1 22FEB2009      .        .

2 27NOV2008  06DEC2008 01JAN2009

2 08DEC2008  06DEC2008 01JAN2009

2 22DEC2008  06DEC2008 01JAN2009

2 30JAN2009      .        .

2 30MAR2009      .        .

;

run;

Thanks,

Vi.

.            .

Accepted Solutions
Solution
‎01-11-2013 07:39 AM
Super Contributor
Posts: 301

## Re: Imputing next visit using LOCF

...adding extra variables (x1 x2) using LAG function is an option.

data have2;

set have;

x1=lag(start);

x2=lag(stop);

output;

run;

data want;

set have2;

if visit > stop and (x1 or x2) ne . then do;

start=x1;

stop=x2;

end;

run;

All Replies
Solution
‎01-11-2013 07:39 AM
Super Contributor
Posts: 301

## Re: Imputing next visit using LOCF

...adding extra variables (x1 x2) using LAG function is an option.

data have2;

set have;

x1=lag(start);

x2=lag(stop);

output;

run;

data want;

set have2;

if visit > stop and (x1 or x2) ne . then do;

start=x1;

stop=x2;

end;

run;

🔒 This topic is solved and locked.