I have sucessfully used regexm to search for one string (a diagnose code, for example "I33.0") among many observations in a variable (called "diagnosis").
I created a new variable (endocarditis) that is given the value 1 if there was a match.
Code:
replace endocarditis = regexm(diagnosis, "I33.0")
Now I want to do the exact same thing, but instead of searching for one string, I want to search for many strings (I33.0", "I33.9", "B37.6").
If there is a match on any of these diagnose codes, I want the new variable "endocarditis" to be given the value 1.
The strings I want to search for are stored in a variable ("X") in the same dataset.
I would very much appreciate if I could get help to loop regexm to search the variable "diagnosis" for each observation in "X".
I want the data to look as follows:
X | diagnosis | endocarditis |
I33.0 | A367 B12.3 B37.6 | 1 |
B37.6 | C45.6 | 0 |
I33.9 | S536 F6349 | 0 |
Niko Vähäsarja
Karolinska Institutet
0 Response to Loop regexm to search for multiple strings stored as observations
Post a Comment