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;
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!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: