DATA Step, Macro, Functions and more

visitnum carry forward locf

Reply
Occasional Contributor
Posts: 15

visitnum carry forward locf

if subject had VISITNUM=4 as early termination (ET) visit and no Visit 3 record then re-assign ET visit to the closest post baseline planned visit and keep the reported data as for analysis as well:  Visit 2/Day 28 (24-32 Days), Visit 3/Day 56 (52-60 Days), Visit 4/Day 84 (80-88 Days). If ET visit is mapped to other than Visit 4 then value is carried forward to Visit 4. 
data exp;
length id $10 num 8 visit $30;
infile datalines dsd truncover ;
input id $ num visit $;
datalines;
0087 ,2,V2 Day 28
0087 ,3,V3 Day 56
0088 ,2,V2 Day 28
0088 ,4,V4 Day 84_EOT_ET
0097 ,2,V2 Day 28
0099 ,2,V2 Day 28
0099 ,4,V4 Day 84_EOT_ET
0100 ,2,V2 Day 28
0100 ,3,V3 Day 56
;
run;

 

i want bellow the output visitnum had 2 and 3  here 3 is carry forward same subj visitnum 4 how to do it .
0087,2,V2 Day 28
0087,3,V3 Day 56
0087,4,V3 Day 56,locf
0088,2,V2 Day 28
0088,3,V2 Day 28,locf
0088,4,V4 Day 84_EOT_ET
0097,2,V2 Day 28
0097,3,V2 Day 28,locf
0097,4,V2 Day 28,locf
0099,2,V2 Day 28
0099,3,V2 Day 28,locf
0099,4,V4 Day 84_EOT_ET
0100,2,V2 Day 28
0100,3,V3 Day 56
0100,3,V3 Day 56
0100,4,V3 Day 56,locf

Super User
Super User
Posts: 9,416

Re: visitnum carry forward locf

Seems pretty straight forward, what have you tried? Something like:

proc sort data=have out=subj nodupkey;
  by id;
run;
data subj;
  set subj;
  do num=2 to 4;
    output;
  end;
run;
proc sql;
  create table want as 
  select coalesce(a.id,b.id) as id, 
         coalesce(a.num.num) as num,
         a.visit
  from    have a
  full join subj
  on     a.id=b.id
  and    a.numb=b.num;
quit;
data want;
set want;
retain lstv;
if visit ne "" then lstv=visit;
else visit=cats(lstv,"_locf");
run;

This will expand your data with the missing rows, so every subject will then have the 2,3,4 rows, but visit will be missing from those merged in.  A simple retain then to populate the previous visit.

Ask a Question
Discussion stats
  • 1 reply
  • 81 views
  • 0 likes
  • 2 in conversation