Solved
Contributor
Posts: 25

Creating a New Variable if Death_Date is present

[ Edited ]

Hello,

I want to create a dummy variable for the patient data.

Patients 10002, 10003, 10004 were dead, and

Patients 10005, 10006, 10007 have survived so far.

-----------------------------------------------

Patient_ID      Death_Date

10002            2013-06-04

10003            2011-08-15

10004            2012-12-14

10005

10006

10007

---------------------------------------------

Depending on if Death_Date is present or not, I want to make  a new variable DEATH (1= Death, 0=Surived)

so I tried the following:

data w.patient;

set w.patient;

Death=.;

if (Death_Date=".") then Death = 1

if (Death_Date=" ") then Death = 0

run;

However, it is marking all the death

What have I done wrong?

Any advice or help would be appreciated.

Thank you.

P.S Ultimately, I want to make my data set as  the following:

-----------------------------------------------

Patient_ID      Death_Date     Death

10002            2013-06-04           1

10003            2011-08-15           1

10004            2012-12-14           1

10005                                         0

10006                                         0

10007                                         0

---------------------------------------------

Accepted Solutions
Solution
‎07-20-2016 08:21 PM
Super User
Posts: 10,770

data w.patient;

set w.patient;

if missing(Death_Date) then Death = 0 ;

else Death = 1;

run;

All Replies
Solution
‎07-20-2016 08:21 PM
Super User
Posts: 10,770

data w.patient;

set w.patient;

if missing(Death_Date) then Death = 0 ;

else Death = 1;

run;

Super User
Posts: 9,599

Just to add to your great solution @Ksharp, this would be a great example for the IFN/IFC functions - i.e. a binary yes or no choice:

```data w.patient;
set w.patient;
death=ifn(missing(Death_Date),0,1);
run; ```
Contributor
Posts: 25

Thank you so much!!

Super User
Posts: 23,685

Re: Creating a New Variable if Death_Date is present

It depends on your variable type, numeric or character.

In character variables missing is represented as a blank, and this can be denoted with empty quotes ("")

A numeric variable has a . when missing and you can check for this with (.) no quotation marks required.

``If date_char = "" then death = 0; else death = 1;``
``If date_num = . Then death = 1; else death =0;``

Or you can bypass that issue entirely and use the MISSING() function as demonstrated in @Ksharp code. Personally I like that option as it's easy to read.

☑ This topic is solved.