BookmarkSubscribeRSS Feed
malena
Calcite | Level 5

Hello, I a trying to only keep the records with any diagnosis of drug overdose.
The ICD-10-CM diagnosis codes used to identify drug overdose included:

1) ICD-10-CM range T36-T50: Poisoning by drugs, medicaments and biological substances
AND
2) a 5th/6th character of:
1: Accidental (unintentional)
2: Intentional self-harm
3: Assault
4: Undetermined intent

Note: For T369, T37.9, T39.9, T41.4, T42.7, T43.9, T45.9, T47.9, and T49.9, a
5th character for all others, a 6th character

AND
3) a 7th (last) character of A (initial encounter of care) or missing/*

/*;

 

 

the data looks like this:

Data test;

input ID $PDIAG10 $DIAG_1 $DIAG_2 $DIAG_3 $DIAG_4 $DIAG_5 $DIAG_6 $DIAG_7 $DIAG10_8
$DIAG_9 $DIAG_10 $DIAG_11 $DIAG_12 $DIAG_13 $DIAG_14 ;

datalines;
1 O690XX0 Z370 Z3A39
2 O3421 O321XX0 O09523 Z3A39 Z370 Z302 Z87891
3 O411230 O620 O09523 Z3A39 Z370
4 O403XX0 O9832 Z370 E669 Z3A39 O99214 Z6833 A6009 K429 O09523 O700
5 O34211 Z370 Z3A39
6 O99824 F17210 O09523 Z302 Z370 Z3A37 O99334
7 O1494 O134 O99824 O09523 Z370 Z3A37
8 O34211 O24425 N858 O328XX0 Z3A38 Z370 Z302
9 O4103X0 F329 F17200 Z370 O99334 Z3A39 Z302 O99824 O134 O1214 F419 O99344 H548
10 O99341 F209 O161 O24911 F319 F419 F29 Z794 Z9049 Z9114 Z885 Z9102
11 O76 Z370 Z3A39 T360X2A

12 O10013 O4103X0 T7621XA Z6841 Z370 Z3A37 O99214 E669 O99284 E039 O09523 O34219 Z302 N736 

13 O3421 O1092 O403XX0 O9842 Z6841 O99214 Z370 Z3A38 O09523 Z302 O770 B1920 O99513 J45909 N736
14 O700 Z3A39 Z370
15 O99824 O09523 O80 Z3A40
16 O324XX0 G43709 O76 O6641 J4520 N858 Z370 Z3A39 O34211 O09523 O99824 O9952 O628 O610
17 O6014X0 O99345 Z3A36 Z370 F53 Z23 Z87891 Z885
18 O09523 O9852 O2623 Z370 Z3A38 K219 F329 O99344 O99013 D649 F419 B009 O7589
19 O1493 Z3A37 O3421 O99214 E669 Z6838 Z87891 Z880 Z370 Z23
20 O99344 F419 Z87891 Z3A40 Z370
21 O99810 O403XX0 Z370 O368930 Z3A39
22 O99214 E669 O0933 F17210 Z370 Z3A42 O99334 O09523
23 O6981X0 D649 O660 Z370 Z3A40 O700 O9081 O99820 O09523
24 O1413 O721 O630 O09523 O691XX0 Z3A37 Z370
25 O24425 Z6842 E6601 O99214 O9902 D649 O34212 O321XX0 Z302 Z3A37 Z370
26 O99413 E6601 Z370 O99824 O99214 O09523 Z3A38 O0993 Z6839
27 O2432 E118 O10913 Z3A38 Z370 O7581 Z302 O09523 Z23 Z79899 Z7984
28 O76 O3421 O09523 Z3A38 Z370 Z302 Z880
29 O112 E0500 O1002 O99284 Z3A26 Z79899 Z370 Z23
30 O99324 F1490 O99334 F17210 O9902 D649 Z3A34 Z370 Z302
31 O1092 O24420 O34211 Z3A36 Z7984 Z85850 Z370 Z7982
32 O9902 O09523 Z3A36 Z370
33 O411230 Z3A40 Z370
34 O480 O753 O321XX0 O9902 D6489 Z79899 T8144XA
35 O701 Z370 O26893 Z6741 Z3A39 Z302
36 O34211 O365930 Z370 Z302 Z3A39 O09523 K660 O99344 F419 O99210 E669
37 O623 E669 K219 Z370 Z3A38 O9962 O164 O99214 Z79899
38 O4103X0 O3421 Z3A37 Z370
39 O80 Z23 Z302 Z3A39 Z833 Z8249 Z98890 Z370
40 O42913 O99214 E669 Z6838 O24424 O6981X0 O09523 Z3A34 Z370
41 O82 Z23 Z3A39 Z370 T8144XA T50901A

42 O358XX0 Z370 Z3A39 T8144XA;
run;

 

 

here is the code I have, but I am not sure if I am getting what I need- not too familiar with PRXMATCH.


data overdose;
set all;

drug_overdose= 0 ;

ARRAY diag (*) $DIAG_1-DIAG_14 ;


DO i= 1 TO dim(diag);
IF
PRXMATCH( "/((T3[679]9|T414|T427|T4[3579]9)[1-4].|(?!(T3[679]9|T414|T427|T4[3579
]9))(T3[6-9]|T4[0-9]|T50)..[1-4])(A|$|\b)/" , diag[i])> 0 THEN drug_overdose= 1 ;
END ;

if drug_overdose= 0 then delete;
run;

4 REPLIES 4
mklangley
Lapis Lazuli | Level 10

Can you give some examples (plural) of diagnosis codes you want to retain?

 

From the data you provided, as I understand your rules, none of the diagnosis codes should be retained, since the code must begin with T36, T37, ... , T50 (which none of your provided data does).

malena
Calcite | Level 5

yes but is the code written correctly?

 

 

mklangley
Lapis Lazuli | Level 10

To confirm that your code is accurate/complete, both types of diagnosis codes should be tested--those that should be deleted, and those that should be retained.  So you'll need both in your input data. Right now, there only seems to be the former.

 

I tried to come up with a few example diagnosis codes that would be retained, based on the rules that you gave. Correct me if I'm wrong on any of these:  T36919A, T41429A, T42739, and T50994A.  I've added these in input rows 43-46 below, and ran this slightly modified code:

data test;
    infile datalines missover;
    input ID PDIAG10 $ DIAG_1 $ DIAG_2 $ DIAG_3 $ DIAG_4 $ DIAG_5 $ DIAG_6 $ DIAG_7 $ DIAG_8 $ DIAG_9 $ DIAG_10 $ DIAG_11 $ DIAG_12 $ DIAG_13 $ DIAG_14 $;
    datalines;
1 O690XX0 Z370 Z3A39                                
2 O3421 O321XX0 O09523 Z3A39 Z370 Z302 Z87891               
3 O411230 O620 O09523 Z3A39 Z370
4 O403XX0 O9832 Z370 E669 Z3A39 O99214 Z6833 A6009 K429 O09523 O700
5 O34211 Z370 Z3A39
6 O99824 F17210 O09523 Z302 Z370 Z3A37 O99334
7 O1494 O134 O99824 O09523 Z370 Z3A37
8 O34211 O24425 N858 O328XX0 Z3A38 Z370 Z302
9 O4103X0 F329 F17200 Z370 O99334 Z3A39 Z302 O99824 O134 O1214 F419 O99344 H548
10 O99341 F209 O161 O24911 F319 F419 F29 Z794 Z9049 Z9114 Z885 Z9102
11 O76 Z370 Z3A39
12 O10013 O4103X0 O365930 Z6841 Z370 Z3A37 O99214 E669 O99284 E039 O09523 O34219 Z302 N736
13 O3421 O1092 O403XX0 O9842 Z6841 O99214 Z370 Z3A38 O09523 Z302 O770 B1920 O99513 J45909 N736
14 O700 Z3A39 Z370
15 O99824 O09523 O80 Z3A40
16 O324XX0 G43709 O76 O6641 J4520 N858 Z370 Z3A39 O34211 O09523 O99824 O9952 O628 O610
17 O6014X0 O99345 Z3A36 Z370 F53 Z23 Z87891 Z885
18 O09523 O9852 O2623 Z370 Z3A38 K219 F329 O99344 O99013 D649 F419 B009 O7589
19 O1493 Z3A37 O3421 O99214 E669 Z6838 Z87891 Z880 Z370 Z23
20 O99344 F419 Z87891 Z3A40 Z370
21 O99810 O403XX0 Z370 O368930 Z3A39
22 O99214 E669 O0933 F17210 Z370 Z3A42 O99334 O09523
23 O6981X0 D649 O660 Z370 Z3A40 O700 O9081 O99820 O09523
24 O1413 O721 O630 O09523 O691XX0 Z3A37 Z370
25 O24425 Z6842 E6601 O99214 O9902 D649 O34212 O321XX0 Z302 Z3A37 Z370
26 O99413 E6601 Z370 O99824 O99214 O09523 Z3A38 O0993 Z6839
27 O2432 E118 O10913 Z3A38 Z370 O7581 Z302 O09523 Z23 Z79899 Z7984
28 O76 O3421 O09523 Z3A38 Z370 Z302 Z880
29 O112 E0500 O1002 O99284 Z3A26 Z79899 Z370 Z23
30 O99324 F1490 O99334 F17210 O9902 D649 Z3A34 Z370 Z302
31 O1092 O24420 O34211 Z3A36 Z7984 Z85850 Z370 Z7982
32 O9902 O09523 Z3A36 Z370
33 O411230 Z3A40 Z370
34 O480 O753 O321XX0 O9902 D6489 Z79899 T8144XA
35 O701 Z370 O26893 Z6741 Z3A39 Z302
36 O34211 O365930 Z370 Z302 Z3A39 O09523 K660 O99344 F419 O99210 E669
37 O623 E669 K219 Z370 Z3A38 O9962 O164 O99214 Z79899
38 O4103X0 O3421 Z3A37 Z370
39 O80 Z23 Z302 Z3A39 Z833 Z8249 Z98890 Z370
40 O42913 O99214 E669 Z6838 O24424 O6981X0 O09523 Z3A34 Z370
41 O82 Z23 Z3A39 Z370 T8144XA
42 O358XX0 Z370 Z3A39 T8144XA
43 T36919A A123  
44 T41429A B456
45 C789 T42739
46 T50994A D123
    ;
run;

data overdose;
    set test;
    drug_overdose = 0 ;
    array diag (*) $ pdiag10 diag_1-diag_14 ;
    do i = 1 to dim(diag);
        if prxmatch("/((T3[679]9|T414|T427|T4[3579]9)[1-4].|(?!(T3[679]9|T414|T427|T4[3579]9))(T3[6-9]|T4[0-9]|T50)..[1-4])(A|$|\b)/", diag[i])> 0 
            then drug_overdose = 1;
    end ;
    if drug_overdose = 0 then delete;
run;

(Note that I included PDIAG10 in the array above. Change that, if you only want DIAG_1 through DIAG_14 to be checked for that code.)

 

If it's your intent that, for any row where one such diagnosis code is found, the entire row is retained (regardless of the other diagnosis codes), then that code works for these examples. 

 

But it's possible there are some gaps in my comprehension of what codes need to be retained. If you could supply more diagnosis code examples that should be kept, they would be very straightforward to test. Those would be helpful for testing your PRXMATCH thoroughly.

malena
Calcite | Level 5

thank you- will try these and test it with new codes

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 862 views
  • 1 like
  • 2 in conversation