BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jennxxness
Calcite | Level 5

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_IDHFHF_dateMIMI_dateStrokeStroke_date
10.131DEC2019106AUG2005

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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


 

View solution in original post

2 REPLIES 2
Reeza
Super User
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


 

jennxxness
Calcite | Level 5
Thank you so much!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 436 views
  • 0 likes
  • 2 in conversation