Tuesday 20 February 2018

concept of LOCF WOCF BOCF MIN MAX

data HAVE;
input SUBJID  VISITN   AVAL;
cards;
001  1  26
001  2  41         
001  3  35
002  1  12
002  2  21
003  1  22
;
run;

/*locf*/
data want;
set have;
by SUBJID;
output;
if last.SUBJID;
DTYPE="LOCF";
if VISITN<5
then do VISITN = VISITN+1 to 5;
output;
end;
run;
/*wocf*/
proc sort data=have out=ds;
by subjid aval;
run;

data wocf;
set ds;
by subjid;
output;
if last.subjid=1;
dtype="wocf";
if visitn <5 then  do
visitn=visitn+1 to 5;
output;
end;
run;
proc sort data=wocf;
by subjid visitn aval;
run;

/*bocl*/
data base;
input id visit$ aval;
cards;
101 scr  20
101 base 25
101 v1   25
101 v2   26
102 scr  25
102 base 30
102 v1   25
102 v2   30
103 scr  23
103 base 33
;
run;

proc sort data=base out=base2;
by id decending visit ;
run;

data bocf;
set base2;
by id ;
if first.id=1 then seq=1;
else seq+1;
output;
if last.id=1;
dtype="bocf";
if seq <5 then do
seq=seq+1 to 5;
output;
end;
run;

proc sort data=bocf out=bocf1;
by id aval;
run;

data avg base1 post;
set base;
by id ;
if first.id=1 then seq=1;
else seq+1;
if  seq > 2 then output post;
else output base1;
run;
data ret;
set post;
by id;
if first.id=1 then x=aval;
else x+aval;
run;

No comments:

Post a Comment