BookmarkSubscribeRSS Feed
centro_9
Calcite | Level 5

Hi everyone

I need to get type 2 diabetes patients from claims data by using ICD 9 AND 10 Codes.

when I ran the following code I got Type 1 diabetes patients as well because ICD9 codes of type 2 and 1 start with 250. 

data Array;
set MED;
array d(9)$ MEDICAL_PRIMARY_DIAGNOSIS_CODE MEDICAL_DIAGNOSIS_CODE_2-MEDICAL_DIAGNOSIS_CODE_9;
do i=1 to 9;
DM=0;
DM1=0; DM2=0;
if substr (d(i),1,3) = 'E11' then DM1=1;
if substr (d(i),1,3) = '250' then DM2=1;
if DM1=1 or DM2=1 then DM=1;
else DM=0;
end;
drop i;
run;
 

For type 1 diabetes I have these icd 9 codes to delete but i incorporate it into the above array code it gave 0 observations.

 

if substr (d(i),1,5) IN ('25001', '25003', '25011', '24013', '25021','25023', '25031', '25033', '25041', '25043', '25051','25053', '25061', '25063',
'25071','25073','25081','25083','25091','25093') THEN DM=1;
if DM=1 then delete; 

 

Please guide

1 REPLY 1
ballardw
Super User

First a sort of admin bit. Pasting code into a text/code box opened on the forum with the </> that appears above the message will preserve formatting such as:

 

data Array;
   set MED;
   array d(9)$ MEDICAL_PRIMARY_DIAGNOSIS_CODE MEDICAL_DIAGNOSIS_CODE_2-MEDICAL_DIAGNOSIS_CODE_9;
   do i=1 to 9;
      DM=0;
      DM1=0; 
      DM2=0;
      if substr (d(i),1,3) = 'E11' then DM1=1;
      if substr (d(i),1,3) = '250' then DM2=1;
      if DM1=1 or DM2=1 then DM=1;
      else DM=0;
   end;
   drop i;
run;

If you use any indenting in the code to make it easier to follow, as shown, then the code box preserves that.

 

 

Your logic above fails in what I think you may have attempted because the result of the DO loop is always the result for the last variable in the array.

You can quit a loop on a condition, such as possibly the first time DM=1 by using the LEAVE instruction. Perhaps

 

data Array;
   set MED;
   array d(9)$ MEDICAL_PRIMARY_DIAGNOSIS_CODE MEDICAL_DIAGNOSIS_CODE_2-MEDICAL_DIAGNOSIS_CODE_9;
   do i=1 to 9;
      DM=0;
      DM1=0; 
      DM2=0;
      if substr (d(i),1,3) = 'E11' then DM1=1;
      if substr (d(i),1,3) = '250' then DM2=1;
      if DM1=1 or DM2=1 then do;
           DM=1;
           leave;
      end;
      else DM=0;
   end;
   drop i;
run;

Or do not keep resetting DM to 0. Only set it to 1 when you want. SAS does not require initializing variables.

 

You would have to show the entire data step where you attempted to use the IN operator to see but I suspect the exact same issue as above with having your DM set from the last variable in the array, which I also suspect is often missing.

 

Note if you get tired of

 if substr (d(i),1,3) = 'E11' 

the =: operator, not the : immediately after the =, is "begins with" and you could use

 if d(i) =: 'E11' 

The comparison will only use the number of characters on the right side of the =: so you do not need the explicit Substr call.