BookmarkSubscribeRSS Feed
deleted_user
Not applicable
HI everyone..

I have a dataset baseline with variables which I merge with other dosing dataset
by subject.
how can i define new baseline variables in new dataset?

basline dataset has variables subject , hdl,ldl,sampdate,trig.
dosing dataset has variables subject,dosedate.

first i did the sorting .
then mergeing.

data new;
merge baseline dosing;
by subject;

i want this new dataset to have variables like..
b_hdl,b_ldl,b_trig.
how do i do that.
the system says the variables are not referenced.if i use keep.
please help.

thanx in advance
april.
3 REPLIES 3
deleted_user
Not applicable
If you are using RENAME and KEEP in one data set, then KEEP should contain the original variable names rather than renamed variable names.

Try this out:-

data new (rename=(hdl=b_hdl ldl=b_ldl trig=b_trig));
merge baseline dosing;
by subject;
keep subject sampledate dosedat hdl ldl trig;
run; Message was edited by: Display name not found
deleted_user
Not applicable
thanx for the solution...

but the problem still stays..

i am writing the coding plz see where i am making a mistake.

the output i want from this dataset is that it should show locf so long as the measures occur withina five day window befor the pill is taken.

code:
*** Input Sample cholesterol data;
***subject=patient number,sampdate=lab sample date,
***hdl=hdl ldl=ldl trig=triglycerides.;

data 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 dosing;
input subject $ dosedate date9.;
cards;
101 07sep2003
102 07oct2003
103 13nov2003
;
run;



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

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

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

proc print data=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;
deleted_user
Not applicable
continued....

*** 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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 3 replies
  • 1258 views
  • 0 likes
  • 1 in conversation