BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
michtka
Fluorite | Level 6

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.

         .            .

1 ACCEPTED SOLUTION

Accepted Solutions
michtka
Fluorite | Level 6

...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;

View solution in original post

1 REPLY 1
michtka
Fluorite | Level 6

...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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1032 views
  • 0 likes
  • 1 in conversation