BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jdr1
Obsidian | Level 7

Dear SAS Community,

 

I'm revising an algorithm that labels all hospital delivery discharges for over ten years as having my condition of interest (composite of 21 conditions). The first step involves updating one of the conditions "sepsis" with the following ICD10 codes: O85, O86.04, T80.211A, T81.4XXA, T81.44xx, or R65.20 or A40.x, A41.x, A32.7. I'm stuck on how to ensure that the "A" for T81.4XXA gets included. I'm sure it's an easy fix, but don't know the best way to approach. Below is as far as I've gotten. Can anyone point me in the right direction?

 

**note all decimals have been removed from ICD10 codes

label Sepsis_flag = "Sepsis";
Sepsis_flag = 0;
do i=1 to dim(diagvar);
if (diagvar{i} in :('O85','O88604','T80211A','T8144','R6520','A40','A41','A327') and substr(diagvar,7,1)= "A"
then Sepsis_flag =1;
end;

 

1 ACCEPTED SOLUTION

Accepted Solutions
jdr1
Obsidian | Level 7

Got it! Tom - you're AWESOME. Thank you so, so much for your help!

View solution in original post

10 REPLIES 10
andreas_lds
Jade | Level 19

Please post an example of the data you have, what you get right now and what you need to visualize what "I'm stuck on how to ensure that the "A" for T81.4XXA gets included." means.

Astounding
PROC Star
First, clean up the code. Some items in the IN list don't match anything mentioned in your question.

Second, do you understand what the colon does here?

in : (

If the final list were to include this:

'T814'

that would be sufficient to include T81.4XXA but it's not clear whether this constitutes a typo:

T8144

And it's not clear why the second condition about substr,7,1 should be part of the program at all.

Once the errors are cleared up, there will be ways to speed up the process.
jdr1
Obsidian | Level 7

Hi Astounding, 

 

Thanks so much for your helpful suggestions! I have two options for my ICD10 codes (ICD10 short and ICD10 long). I'm so nervous that I'm not going to catch a code and typically misuse the "in 😞 ". 

 

Here is my question/lack of understanding:

 

Say I use in : ('T814'). Can I assume that only "T814xxA" will labeled as sepsis or "T814xxB" or "T814xxC" will also be labeled as sepsis. Do I really need to tell SAS to make sure that any of the "T814" diagnosis codes must end with an A to be labeled as sepsis? This is what I was trying to do with the substring function. 

 

 

ScottBass
Rhodochrosite | Level 12

Post representative data using a self-contained data step using datalines (or otherwise something I can cut-and-paste into SAS).

Show how you're creating the diagvar array.

Is substr(diagvar,7,1) a typo?  Should it be diagvar{i}?

When I've done this in the past I've just used a format or informat.  Just put all your desired values in an informat, return 1 for matches, 0 for _other_, and using the input function on your data.

 


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
jdr1
Obsidian | Level 7

Dear ScottBass,

 

Thank you so much for the quick response. I really appreciate it. Below is a response to your questions:

 

Representative data: 

Data test;

input ID $ PDIAG10 $ SDIAG10_1  $ SDIAG10_2 $ SDIAG10_3 $ SDIAG10_4 $ SDIAG10_5 $ SDIAG10_6 $ SDIAG10_7 $ SDIAG10_8 $ SDIAG10_9 $ SDIAG10_10 $ SDIAG10_11 $ SDIAG10_12 $ SDIAG10_13 $ SDIAG10_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 Z3A40 
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 O114 E669 Z370 Z3A26 Z9114 O99214 O34219 Z8673 Z6838 F40240 K219 O99613 M4800 O76 O321XX0
44 O1493 H10021 O9953 J029 O09529 Z3A40 Z370 
45 O80 Z370 T8144XA
46 O99824 O09523 Z3A39 Z370 Z87891 Z302 
47 O320XX2 D62 Z372 O99214 E6601 O30043 O9903 O76 O322XX1 O09523 O0933 O09213 Z6838 Z3A38 
48 O3421 O9902 O30123 O722 Z3751 Z6842 O1093 Z302 Z3A34 D649 O99214 E669 
49 O360930 O9902 Z370 Z3A40 O09523 Z8673 Z9114 Z30017 
50 O623 O9903 D62 O9902 O09523 Z370 Z3A37 O3413 D259 

;

run;

 

Here is how I set up the diagvr array:

%let dsn= test;
%let DiagCodes= PDIAG10 SDIAG10_1 SDIAG10_2 SDIAG10_3 SDIAG10_4 SDIAG10_5 SDIAG10_6 SDIAG10_7 SDIAG10_8 SDIAG10_9 SDIAG10_10 
SDIAG10_11 SDIAG10_12 SDIAG10_13 SDIAG10_14;
%let ProcCodes =  SPROC10_1 SPROC10_2 SPROC10_3 SPROC10_4 SPROC10_5 SPROC10_6 SPROC10_7 SPROC10_8 SPROC10_9 SPROC10_10 SPROC10_11 SPROC10_12;
%let DRG= MSDRG;
**MS or APR;
%let DRGtype= MS;
data DeliveryHosps10;
set &dsn;
/*Set up arrays for diagnoses, procedure and DRG vars*/
	array diagvar {*} &DiagCodes;
	array procvar {*} &ProcCodes;
	array drgvar {*} &DRG;

Re: Is substr(diagvar,7,1) a typo?  Should it be diagvar{i}? Yes, diagvar was a typo (insert sheepish grin)

 

When I've done this in the past I've just used a format or informat.  Just put all your desired values in an informat, return 1 for matches, 0 for _other_, and using the input function on your data. Can you provide an example? I just have 21 seperate conditions (like the sepsis variable in my question) that are comprised of 10 to 15 separate ICD10 codes. All these 21 conditions make up my composite condition that I'm most interested in.  I just don't yet know the best way to approach this. 

Tom
Super User Tom
Super User

Your test is checking only for codes that end in A.  Is that what you want?  

Looks like you just need to make different test for different types of codes.

Some are fully specified:

diagvar{i} in ('T80211A')

Some are just prefixes:

diagvar{i} in :('O85','O88604','T8144','R6520','A40','A41','A327') 

And some are complex:

diagvar{i} in :('T814') and char(diagvar{i},7)='A'

Just OR the different test together.

jdr1
Obsidian | Level 7

Hi Tom. 

 

THANK YOU much for your suggestion! I tried to "OR" at first, but couldn't structure it correctly and received an error message. So is this the correct way:

 

*Note: it's the silly, tiny things that I always get tripped up on 🙂 

label Sepsis_flag = "Sepsis";
	Sepsis_flag = 0;
		do i=1 to dim(diagvar);
	if diagvar{i} in ('T80211A') or diagvar{i} in :('O85','O88604','T8144','R6520','A40','A41','A327')  or diagvar{i} in :('T814') and char(diagvar{i},7)='A'
		then Sepsis_flag =1;

 

 

Tom
Super User Tom
Super User
Add parentheses around the conditions that are combined via OR.
(test1) or (test2) or (test3a and test3b)
jdr1
Obsidian | Level 7

Got it! Tom - you're AWESOME. Thank you so, so much for your help!

andreas_lds
Jade | Level 19

Should should have marked any of Toms post as solution, not your own post.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1906 views
  • 1 like
  • 5 in conversation