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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.