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

I want to use two variables in my data set (CauseofDeath and ContributingFactorsofDeath) to create a new variable: COVDeathsBiobank

I'm not sure I'm translating this correctly into code. Here is what I am trying to do in words:

If the CauseofDeath contains the string "COV" AND/OR if ContributingFactorsofDeath=U07.1,

then COVDeathsBiobank=1

If both of these statements are false I wanted COVDeathsBiobank=0

 

There are some observations with just the first condition true, some with just the second condition true, and some with both true. Here is what I have:

DATA Aim1;
	SET Variables;
IF prxmatch("/COV/",CauseofDeath)  THEN COVDeathsBiobank=1;
IF ContributingFactorsofDeath= "U07.1" THEN COVDeathsBiobank=1;
	ELSE     COVDeathsBiobank=0;
RUN;

I'm trying to make sure I don't accidentally exclude observations that for example meet the second criteria but are coded as 0 in COVDeathsBiobank because the first criteria is false. Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Without actual data it is hard to confirm though I might suggest an additional else so if the value is set with the first comparison you do not reset it with the following comparisons.

 

DATA Aim1;
	SET Variables;
IF prxmatch("/COV/",CauseofDeath)  THEN COVDeathsBiobank=1;
ELSE IF ContributingFactorsofDeath= "U07.1" THEN COVDeathsBiobank=1;
	ELSE     COVDeathsBiobank=0;
RUN; 

 

View solution in original post

2 REPLIES 2
ballardw
Super User

Without actual data it is hard to confirm though I might suggest an additional else so if the value is set with the first comparison you do not reset it with the following comparisons.

 

DATA Aim1;
	SET Variables;
IF prxmatch("/COV/",CauseofDeath)  THEN COVDeathsBiobank=1;
ELSE IF ContributingFactorsofDeath= "U07.1" THEN COVDeathsBiobank=1;
	ELSE     COVDeathsBiobank=0;
RUN; 

 

abrice520
Obsidian | Level 7
Thank you this was exactly what I needed!

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 16. 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
  • 487 views
  • 0 likes
  • 2 in conversation