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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 2 replies
  • 654 views
  • 0 likes
  • 2 in conversation