Hi All,
Can anyone help me with an example SAS code of BOCF (Best Observation Carry Forward) in clinical trials? I have tried searching Google and https://www.lexjansen.com/ but except for theoretical explanation, I couldn't find any example code explaining the concept. It will be very helpful, if anyone can explain BOCF with an example code.
Thanks
Some example data in the form of a data step and the expected results will go a long way. Also a clear definition of what is a "best observation" for your use and based on the example data. "Best" is a value judgement in many cases and does not always have the same values given the concern(s) of interest.
Actually, it is Baseline Observation Carry Forward. As found in Google, it is defined as "The baseline observation carry forward (BOCF) method, in which baseline observations are treated as the final responses from patients without any post-baseline observation or patients who drop out after the first post-baseline treatment, has been suggested for certain such studies by some regulatory agencies.".
I don't have example data, but want help with this, if anyone can help me with an example of BOCF.
Thanks
Best Observation Carry Forward??
Never heard about that. ☹️
But ... Last Observation Carry Forward (LOCF) : that's a very popular method for dealing with missing data in longitudinal data. If you search these SAS Communities for LOCF keyword, you will have numerous hits (and numerous code examples)!
By the way, are you sure BOCF is "Best Observation Carry Forward"? What is "Best"?
Maybe it is baseline-observation-carried-forward (BOCF), ... that approach is one method to handle missing data from early treatment discontinuation.
If you give a bit more info on what exactly you try to achieve, we may be able to provide better help.
Koen
Yes, you are right that it is Baseline Observation Carry Forward. Any example code explaining this concept, will be a great help.
Thanks
Let's say you data set HAVE is sorted by ID and DATE (BTW, will a date be repeated? that will add complications). And it also has variables RESULT, a,b,c,x,y,z.
And by "best" result you mean the maximum (to date) of variable RESULT.
And let's also say you also want to carry forward a subset of the other variables from the observation that has the best result (but renamed to avoid collision with values in the record-in-hand). Say variables X Y and Z.
Untested, in the absence of sample data:
data bocf;
set have ;
by ID;
if first.id then call missing(of best_result);
if result>best_result then set have (keep=result x y z
rename=(result=best_result x=best_result_x y=best_result_y z=best_result_z))
point=_n_;
run;
The variable BEST_RESULT is being treated as a retained variable, even though there is no explicit RETAIN statement. This is because, like all variables read via the SET statement, it is automatically retained. Now most variables read by SET are replaced in every iteration of the DATA step, because the corresponding SET is executed in every iteration (the initial SET HAVE above). But the BEST_RESULT variable, and the other BEST_RESULT_... vars, are read in only occasionally, so are retained until replaced when the "if result>best_result" test is met.
Thank you very much for the reply. I will try if I can use this example to BOCF (Baseline Observation Carry Forward).
It's baseline (not "best") observation carried forward?
Then. if baseline data is always the first obs for each id:
data bocf;
set have ;
by ID;
if first.id then set have (keep=result x y z
rename=(result=baseline_result x=baseline_x y=baseline_y z=baseline_z))
point=_n_;
run;
Thank you. I will try this.
It is usually BASELINE that is carried forward so that you can do a change from baseline analysis.
If the BASELINE reading is always recorded on the same VISIT then a simple MERGE will do and there is no need "carry forward" anything.
data want;
merge have
have(keep=id score visit rename=(score=baseline visit=bvisit)
where =(bvisit=1))
;
by id;
change = score-baseline;
run;
Otherwise if finding the baseline value is more difficult then you will need to carry the baseline value forward by using a retained variable. So if SCORE is always there are you want to use the first value as the BASELINE then something like this is enough.
data want;
set have;
by id date ;
if first.id then baseline=score;
retain baseline;
change = score-baseline;
run;
But if score might be missing then you might need something more complicated.
data want;
set have;
by id date ;
if first.id then baseline=.;
retain baseline;
baseline=coalesce(baseline,score);
if n(score,baseline)=2 then change = score-baseline;
run;
Thank you very much Tom, for a very detailed explanation. I will try all these cases.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.