I am a beginner SAS user and would really appreciate some help.
This is an example of the dataset I have for several thousands of patients:
Patient_ID | HF | HF_date | MI | MI_date | Stroke | Stroke_date |
1 | 0 | . | 1 | 31DEC2019 | 1 | 06AUG2005 |
HF=Heart Failure, MI=Myocardial Infarction
I am working on a survival analysis and will need to do it for a composite outcome called MACE (which will the 3 variables in my dataset: HF, MI and stroke).
I am trying to find the best way to create a MACE_date that reflects the earliest date if a patient has more than 2 outcomes. So for patient 1 above, I would want the MACE_date to be 06AUG2005 instead of 31DEC2019.
I currently have:
MACE=0;
if HF=1 then MACE=1;
if MI=1 then MACE=1;
if stroke=1 then MACE=1;
MACE_date=.;
if HF=1 then MACE_date=HF_date;
if MI=1 then MACE_date=MI_date;
if Stroke=1 then MACE_date=Stroke_date;
How can I code my SAS in a way where if a patient has multiple outcomes (HF and MI and stroke), that the MACE_date will reflect the earliest date? Is there an easy way to do this?
Thank you so much in advance
MACE=0;
if max(HF, MI, STROKE) = 1 then MACE=1;
MACE_date=.;
if MACE =1 then MACE_DATE = min(HF_Date, MI_Date, STROKE_DATE);
Use the MIN/MAX functions.
Your first condition can be simplified to checking if the max of any of the variables (assuming they take only ., 0, 1) are 1 and you can simplify the last portion to take the minimum. Missing values are ignored.
@jennxxness wrote:
I am a beginner SAS user and would really appreciate some help.
This is an example of the dataset I have for several thousands of patients:
Patient_ID HF HF_date MI MI_date Stroke Stroke_date 1 0 . 1 31DEC2019 1 06AUG2005 HF=Heart Failure, MI=Myocardial Infarction
I am working on a survival analysis and will need to do it for a composite outcome called MACE (which will the 3 variables in my dataset: HF, MI and stroke).
I am trying to find the best way to create a MACE_date that reflects the earliest date if a patient has more than 2 outcomes. So for patient 1 above, I would want the MACE_date to be 06AUG2005 instead of 31DEC2019.
I currently have:
MACE=0;
if HF=1 then MACE=1;
if MI=1 then MACE=1;
if stroke=1 then MACE=1;
MACE_date=.;
if HF=1 then MACE_date=HF_date;
if MI=1 then MACE_date=MI_date;
if Stroke=1 then MACE_date=Stroke_date;
How can I code my SAS in a way where if a patient has multiple outcomes (HF and MI and stroke), that the MACE_date will reflect the earliest date? Is there an easy way to do this?
Thank you so much in advance
MACE=0;
if max(HF, MI, STROKE) = 1 then MACE=1;
MACE_date=.;
if MACE =1 then MACE_DATE = min(HF_Date, MI_Date, STROKE_DATE);
Use the MIN/MAX functions.
Your first condition can be simplified to checking if the max of any of the variables (assuming they take only ., 0, 1) are 1 and you can simplify the last portion to take the minimum. Missing values are ignored.
@jennxxness wrote:
I am a beginner SAS user and would really appreciate some help.
This is an example of the dataset I have for several thousands of patients:
Patient_ID HF HF_date MI MI_date Stroke Stroke_date 1 0 . 1 31DEC2019 1 06AUG2005 HF=Heart Failure, MI=Myocardial Infarction
I am working on a survival analysis and will need to do it for a composite outcome called MACE (which will the 3 variables in my dataset: HF, MI and stroke).
I am trying to find the best way to create a MACE_date that reflects the earliest date if a patient has more than 2 outcomes. So for patient 1 above, I would want the MACE_date to be 06AUG2005 instead of 31DEC2019.
I currently have:
MACE=0;
if HF=1 then MACE=1;
if MI=1 then MACE=1;
if stroke=1 then MACE=1;
MACE_date=.;
if HF=1 then MACE_date=HF_date;
if MI=1 then MACE_date=MI_date;
if Stroke=1 then MACE_date=Stroke_date;
How can I code my SAS in a way where if a patient has multiple outcomes (HF and MI and stroke), that the MACE_date will reflect the earliest date? Is there an easy way to do this?
Thank you so much in advance
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.