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

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

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

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

data w.patient;

set w.patient;

if missing(Death_Date) then Death = 0 ;

 else Death = 1;

run; 

View solution in original post

4 REPLIES 4
Ksharp
Super User

data w.patient;

set w.patient;

if missing(Death_Date) then Death = 0 ;

 else Death = 1;

run; 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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; 
Reeza
Super User

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. 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2462 views
  • 0 likes
  • 4 in conversation