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

I need help creating a new binary variable from an existing data set. The variable name is deathcauses (Cerebral Vascular Disease Coronary Heart Disease, Cancer, Other, or Unknown). I want to create a new binary variable of 0 = heart-related causes and 1 = other causes. The data set is FraminghamD. Please, I need help with the correct SAS code. Thank you 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
if deathcauses in ('Vascular Disease','Coronary Heart Disease') then binary_variable=1;
else binary_variable=0;
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26
if deathcauses in ('Vascular Disease','Coronary Heart Disease') then binary_variable=1;
else binary_variable=0;
--
Paige Miller
Reeza
Super User

A binary variable can be created using IF/THEN statements. However, without knowing your variable name it's hard to suggest the 'correct' SAS code.

An example would be the following, which creates a binary variable that shows if the sex of a person is male or female.

data want;
set sashelp.class;
if sex='F' then Female=1;
else Female=0;
run;

 


@oniume wrote:

I need help creating a new binary variable from an existing data set. The variable name is deathcauses (Cerebral Vascular Disease Coronary Heart Disease, Cancer, Other, or Unknown). I want to create a new binary variable of 0 = heart-related causes and 1 = other causes. The data set is FraminghamD. Please, I need help with the correct SAS code. Thank you 


 

SuryaKiran
Meteorite | Level 14

if you need to search character string for multiple strings then you can use multiple INDEX() or FIND() or else you can use single PRXMATCH() with multiple substring values listed.

 

data want;
set have;  
  if index(lowcase(charvar),'this') > 0 or 
       index(lowcase(charvar),'that') > 0 or
       index(lowcase(charvar),'other') > 0 then found = 1;
    else found=0;
run;

data want;
set have;
    if prxmatch("m/this|that|other/oi",charvar) > 0 then found=1;
    else found=0;
run;
Thanks,
Suryakiran
novinosrin
Tourmaline | Level 20

Hi @oniume Welcome to the SAS forum and Good morning. Please post sample of data that you HAVE and the required output you WANT than just sentences for us to work with in the future. 

 

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
  • 4 replies
  • 11366 views
  • 0 likes
  • 5 in conversation