LOCF coding check.

Reply
N/A
Posts: 0

LOCF coding check.

Hi!!

i am strugling with this.. please check the coding and let me know where i am making a mistake.
i want last obs carried forward in output so long as the measure occurs within a 5 day window before the desired pill is taken.

*** Input Sample cholesterol data;
***subject=patient number,sampdate=lab sample date,
***HDL=HDL,LDL=LDL,TRIG=Triglycerides.;
data jessica.cholesterol_base;
input subject $ sampdate date9. hdl ldl trig;
cards;
101 05sep2003 48 188 108
101 06sep2003 49 185 .
102 01oct2003 54 200 350
102 02oct2003 52 . 360
103 10nov2003 . 240 900
103 11nov2003 30 . 880
103 12nov2003 32 . .
103 13nov2003 35 289 930
;
run;


***input sample pill dosing date;
***subject=patient number,dosedate=drug dosing date;
data jessica.dosing;
input subject $ dosedate date9.;
cards;
101 07sep2003
102 07oct2003
103 13nov2003
;
run;



*** sorting cholesterol data for merging with dosing data;
proc sort data=jessica.cholesterol_base;
by subject sampdate;
run;

***sorting dosing data for merging with cholesterol data.;
proc sort data=jessica.dosing;
by subject;
run;

***DEFINE BASELINE HDL,LDL,TRIG VARIABLES.;
data jessica.baseline(rename=(hdl=b_hdl ldl=b_ldl trig=b_trig));
merge jessica.cholesterol_base jessica.dosing;
by subject;
keep subject hdl ldl trig;
run;

proc print data=jessica.baseline;
run;

*** setup array for baseline variables and lab values.;
array base{3} b_hdl b_ldl b_trig;
array chol{3} hdl ldl trig;

*** retain new baseline variables so they are present at last.subject below.;
retain b_hdl b_ldl b_trig;

*** initialize baseline variable to missing.;
if first.subject then
do i= 1 to 3;
base{i} = .;
end;

*** if labvalue is within 5 days of dosing,retain it as a valid baseline.;
if 1 <=(dosedate-sampdate)<=5 then
do i = 1 to 3 ;
if chol{i} ne . then
base{i} = chol{i};
end;
*** keep last record per patient holding the locf values.;
if last.subject;
label b_hdl="baseline hdl"
b_ldl="baseline ldl"
b_trig="baseline triglycerides";
run;

Thanx in advance.
april.
Frequent Contributor
Posts: 95

Re: LOCF coding check.

I would suggest not renaming the hdl, ldl and trig variables, but assigning the value when the date criteria is met. When the dosedate - sampdate is less than or equal to 5, then assign the hdl, ldl and trig values to b_hdl, b_ldl, and b_trig. Here's and example:

data jessica.baseline;
merge jessica.cholesterol_base jessica.dosing;
by subject;
keep subject b_:;
if dosedate - sampdate <=5 then do;
b_hdl=hdl;
b_ldl=ldl;
b_trig=trig;
end;
run;

proc print data=jessica.baseline;
run;

Is this what you're looking for?
Ask a Question
Discussion stats
  • 1 reply
  • 322 views
  • 0 likes
  • 2 in conversation