Hello, Have a question on how to write code a macro or an array for the following situation. I have a dataset with a client ID and 25 Diagnosis codes, so 25 variables. I would like to write code using if-then where if any of the 25 diagnosis codes meet a criterion it creates a new variable that flags that row as the criteria are met. For example, I have the following code (note for simplicity I only put 5 diagnosis codes, but in reality, I would be dealing with 25) data have ;
input client dx_cd1 $ dx_cd2 $ dx_cd3 $ dx_cd4 $ dx_cd5 $ ;
datalines ;
1 291 2911 2915 2911 2915
2 292 2923 2924 2924 2924
3 F101 F102 F110 303 291
4 Z345 F181 F191 Z235 Z786
5 Z345 Z235 Z126 Z786 Z235
6 305 304 303 303 2915 292
7 F191 Z786 F161 F102 F101
;
run ; If any of the codes above have a diagnosis code staring with F or is number only (so the 292, 305 etc.) then I want to create a new column that flags that row as 1 else 0. So 0 would be if none of the codes started with an F or is a number. I the above example row 5 (client 5) would be the only one that would get a 0, the others would get a flag of 1. Even when they have codes that have a Z in them they also have codes that have F or a number. One way would be to write code for each dx_cd, e.g. if dx_cd1 in :('292','293','F10','30','F19') OR
dx_cd2 in :('292','293','F10','30','F19') OR
dx_cd3 in :('292','293','F10','30','F19') OR
dx_cd4 in :('292','293','F10','30','F19') OR
dx_cd5 in :('292','293','F10','30','F19') OR then flag ='1'; else flag='0'; But I have 25 of these columns and the diagnosis codes are not just the five iterations I have above, they are way more. Any suggestions on how to code efficiently would be appreciated! Thank you!
... View more