BookmarkSubscribeRSS Feed
Banke
Pyrite | Level 9

Hello everyone, 

 

Please, I want to get patients with type II diabetes by subtracting those with Type I diabetes from the total patients with diabetes (the general code for diabetes is 250 but sub-types are identified by the last 2 digits). I am doing this because the coding for type I is more correct than type 2 and I was instructed to do so. My code doesn't work probably because I

DATA MYHUMANA.MED_DIAG; 
SET MYHUMANA.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;
DO I = 1 TO 10;
IF SUBSTR (DIAG(I),1,3) IN ('250') AND SUBSTR NE (DX1(I),4,2)IN ('03', '11', '13', '21', '23', '31', '33', '41', '43', '51', '53', '61', '63', '71', '73', '81', '83', '91', '93') THEN T2D = 0; /**the codes in the DX1(I),4,2 function are type I diabetes**/
OR SUBSTR (DIAG(I),1,3) IN ('E11')then T1D = 1; 
LABEL T2D ='Type II Diabetes';   
END;
RUN; 

can't use the NE function with substr. Please advice.

 

Thank you

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Either you must review your code yourself and apply the proper logic or supply some example data for us to work with.

 

Regarding your code, for example, you have an OR Statement directly after a semicolon. That will produce an error.

 

I think you want something like this, but I'd be guessing

 

DATA MYHUMANA.MED_DIAG; 
SET MYHUMANA.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;
DO I = 1 TO 10;
IF SUBSTR (DIAG(I),1,3) IN ('250') AND SUBSTR(DX1(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 T2D = 0; 
IF SUBSTR (DIAG(I),1,3) IN ('E11')then T1D = 1; 
LABEL T2D ='Type II Diabetes';   
END;
RUN; 

 

Banke
Pyrite | Level 9
DATA MYHUMANA.MED_DIAGX; 
SET MYHUMANA.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;
DO I = 1 TO 10;
IF SUBSTR (DIAG(I),1,3) IN ('250') AND 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') OR 
SUBSTR (DIAG(I),1,3) IN ('E11')then T2D = 1; 
LABEL T2D ='Type II Diabetes';   
END;
RUN; 

Thank you so much, the "NOT IN" function was what i was looking for, thnks for spotting the error in my code too. I adjusted my code and it worked

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 427 views
  • 0 likes
  • 2 in conversation