You don't need to colon modifier because you the length of your substring and the length of the strings in the value list are the same. The colon modifier won't hurt in your case but it's just not necessary (you don't need a contains that would also match sub-strings).
It's a bit guessing on my side but if I understand right then you want DM set to one if for any of the variable in your array the expression is TRUE.
If that's the case then leave the loop as soon as you you're expression becomes TRUE.
In the code you've posted consider the case where in the very last iteration of the loop below condition becomes TRUE.
IF DM = "" THEN DM = "0";
Here you set DM to 0 no matter if in any of the earlier iterations of the loops DM had been set to 1.
In the code I've posted above DM gets initialized to 0 before the loop starts and within the loop only ever gets set to 1. Because of this you wouldn't have to leave the loop once DM becomes 1 as it will never get reset to 0. But it's not necessary to continue looping once DM is 1 and that's why it's better for performance to just stop looping.
And here the code I've posted above as screen shot
/**INITIATE DIAGOSIS VARIABLE “T2D” AT 0, PATIENTS WITH T2D WILL HAVE A SCORE OF 1**/
DATA DIABETES; /**804,378,068**/
SET MED;
*T2D = "0"; /**a new variable for type II diabetes**/
ARRAY DIAG (*) $ ADMISSION_DIAGNOSIS_CODE MEDICAL_PRIMARY_DIAGNOSIS_CODE
MEDICAL_DIAGNOSIS_CODE_2 - MEDICAL_DIAGNOSIS_CODE_9;
DM = "0";
DO I = 1 TO DIM (DIAG);
IF SUBSTR(DIAG(I),1,3) IN ('250','E11')
OR
SUBSTR(DIAG(I),4,2) NOT IN
('03', '11', '13', '21', '23', '31', '33', '41', '43', '51', '53', '61', '63','71', '73', '81', '83', '91', '93')
THEN
do;
DM = "1";
leave;
end;
END;
LABEL DM =' Type II Diabetes ';
RUN;
And last but not least: In your code with the two IFs without an ELSE DM gets set to 1 if either of the conditions becomes True. I've converted this to single IF statement with an OR operator. If both conditions need to be True then replace the OR with an AND.
... View more