Hello,
I am having a difficult time trying to figure out how to merge the two different variables into one variable.
My data set looks like the following:
ID=> Patient ID
Chemo_Start_Date=> Date when chemotherapy started
Death=> 1=Death 0=Survived
Death_Date=> Date when patient died
Observation_Finish_date=> Date when follow-up is finished
FU_DTH
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ID Chemo_Start_Date Death Death_Date Observation_Finish_Date
10001 2011-08-22 1 2012-03-01 2015-05-30
10002 2010-05-15 0 . 2015-05-30
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The follow-up duration (FU) for patients who died (Death=1) should be the difference in dates between the Chemo_Start_Date and
Death_Date.
The follow-up duration (FU) for patients who survived (Death=0) should be the difference in dates between the Chemo_Start_Date and
Observation_Finish_Date.
So I tried the following:
data w.cancer_DT; set w.cancer;
FU = DATDIF(Chemo_Start_Date, Death_Date, 'ACT/ACT'); where death=1;
run;
data w.cancer_SUR; set w.cancer;
FU = DATDIF(Chemo_Start_Date, Observation_Finish_Date, 'ACT/ACT'); where deat=0;
run;
data w.cancer_All; set w.cancer_DT w.cancer_SUR;
run;
My result looks like the following, which is what I needed:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ID Chemo_Start_Date Death Death_Date Observation_Finish_Date FU_Survival
10001 2011-08-22 1 2012-03-01 2015-05-30 192
10002 2010-05-15 0 . 2015-05-30 841.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
However, is there a way to do this in a simple way without seperating files?
Any help or advice will be greatly appreciated.
Thank you.
data have;
input ID Chemo_Start_Date : yymmdd10. Death Death_Date : yymmdd10. Observation_Finish_Date : yymmdd10.;
format Chemo_Start_Date Death_Date Observation_Finish_Date yymmdd10.;
cards;
10001 2011-08-22 1 2012-03-01 2015-05-30
10002 2010-05-15 0 . 2015-05-30
;
run;
data want;
set have;
FU_Survival=coalesce(Death_Date,Observation_Finish_Date)-Chemo_Start_Date;
run;
Just put an if around it:
data w.cancer;
set w.cancer;
if death=1 then fu=datdif(chemo_start_date,death_date,'act/act');
else fu=datdiff(chemo_start_date,observation_finish_date,'act/act');
run;
Do also note, consitent casing, indentation, and the use of the code window (which is {i} above the post).
Use an IF condition.
If you'll only ever have a death date OR last follow up date use the coalesce function to use whichever variable is not missing.
I included that as FU2 to demonstrate.
Data w.cancer_fu;
Set w.cancer;
If death=1 the FU = death_date - chemo_start_date;
Else if death=0 then FU = observation_finish_date - start_date;
FU2 = coalesce(death_date, observation_finish_date) - start _date;
Run;
PS please don't include please help or urgent in your subject line. It doesn't add anything of value to your question. Preferably, take the time to acknowledge answers and mark questions as solved.
Also for dates, I personally find it easier to just subtract them rather than use datediff(). It's shorter for one.
data have;
input ID Chemo_Start_Date : yymmdd10. Death Death_Date : yymmdd10. Observation_Finish_Date : yymmdd10.;
format Chemo_Start_Date Death_Date Observation_Finish_Date yymmdd10.;
cards;
10001 2011-08-22 1 2012-03-01 2015-05-30
10002 2010-05-15 0 . 2015-05-30
;
run;
data want;
set have;
FU_Survival=coalesce(Death_Date,Observation_Finish_Date)-Chemo_Start_Date;
run;
Thank You all for your advice and Help.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.