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!
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;
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.