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. 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 12561 views
  • 0 likes
  • 5 in conversation