BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
1 REPLY 1
1162
Calcite | Level 5
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?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

Discussion stats
  • 1 reply
  • 805 views
  • 0 likes
  • 2 in conversation