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

Hi, 

 

I'm trying to flag all individuals with diagnosis codes E10, E11, and E13. The problem is, I would like this to include all values for that overarching diagnosis code. So for example, if there are diagnosis codes E11.17, E11.21, E11.34, E10.22, E13.49, I would like to flag any with E10, E11, or E13 to be flagged. My code is below and thanks in advance for any help! 

 

data work.diabetes_control_num;
set work.diabetes_control;
array diag{3} $ diagnosis_1 diagnosis_2 diangosis_3;
array a1c_last{1} a1c2;
do i= 1 to 1;
if a1c_last{i} >= 9 then dm_control=0; else if a1c_last{i}=. then dm_control=.; else dm_control=1;
end;
do i=1 to 3;
if diag{i} = in ("E10", "E11", "E13") then diag_control=1; else diag_control=0;
end;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@RebeccaB_ wrote:

Hi, 

 

I'm trying to flag all individuals with diagnosis codes E10, E11, and E13. The problem is, I would like this to include all values for that overarching diagnosis code. So for example, if there are diagnosis codes E11.17, E11.21, E11.34, E10.22, E13.49, I would like to flag any with E10, E11, or E13 to be flagged. My code is below and thanks in advance for any help! 

 

data work.diabetes_control_num;
set work.diabetes_control;
array diag{3} $ diagnosis_1 diagnosis_2 diangosis_3;
array a1c_last{1} a1c2;
do i= 1 to 1;
if a1c_last{i} >= 9 then dm_control=0; else if a1c_last{i}=. then dm_control=.; else dm_control=1;
end;
do i=1 to 3;
if diag{i} = in ("E10", "E11", "E13") then diag_control=1; else diag_control=0;
end;
run;


Actually almost there. If the values are as you say you could use SCAN or SUBSTR functions to get the first letters from your diag codevalues.

 

if  Scan( diag{i},1,'.') in ("E10", "E11", "E13") then diag_control=1; else diag_control=0;

or

if substr(diag{i},1,3) in ("E10", "E11","E13") then ...

Alternate

Diag_control = ( Scan( diag{i},1,'.') in ("E10", "E11", "E13") );

(Exercise for the interested reader for the similar SUBSTR version).

This assignment works because will assign a 1 for true and 0 for false for any logic comparison.

 

 

You don't want to use "= in (<value list>)" just the "in (<value list>)"

View solution in original post

6 REPLIES 6
ballardw
Super User

@RebeccaB_ wrote:

Hi, 

 

I'm trying to flag all individuals with diagnosis codes E10, E11, and E13. The problem is, I would like this to include all values for that overarching diagnosis code. So for example, if there are diagnosis codes E11.17, E11.21, E11.34, E10.22, E13.49, I would like to flag any with E10, E11, or E13 to be flagged. My code is below and thanks in advance for any help! 

 

data work.diabetes_control_num;
set work.diabetes_control;
array diag{3} $ diagnosis_1 diagnosis_2 diangosis_3;
array a1c_last{1} a1c2;
do i= 1 to 1;
if a1c_last{i} >= 9 then dm_control=0; else if a1c_last{i}=. then dm_control=.; else dm_control=1;
end;
do i=1 to 3;
if diag{i} = in ("E10", "E11", "E13") then diag_control=1; else diag_control=0;
end;
run;


Actually almost there. If the values are as you say you could use SCAN or SUBSTR functions to get the first letters from your diag codevalues.

 

if  Scan( diag{i},1,'.') in ("E10", "E11", "E13") then diag_control=1; else diag_control=0;

or

if substr(diag{i},1,3) in ("E10", "E11","E13") then ...

Alternate

Diag_control = ( Scan( diag{i},1,'.') in ("E10", "E11", "E13") );

(Exercise for the interested reader for the similar SUBSTR version).

This assignment works because will assign a 1 for true and 0 for false for any logic comparison.

 

 

You don't want to use "= in (<value list>)" just the "in (<value list>)"

RebeccaB_
Obsidian | Level 7

Thank you for the help! I've used both scan and substr but all observations of diag_control are still being flagged as "0", but I can visually see an observation that, for example, has diagnosis_1 = E11.21. Any suggestions in changing my code so that I can capture this? 

 

 

CODE: 

data work.diabetes_control_num;
set work.diabetes_control;
array diag{3} $ diagnosis_1 diagnosis_2 diangosis_3;
array a1c_last{1} a1c2;
do i= 1 to 1;
if a1c_last{i} >= 9 then dm_control=0; else if a1c_last{i}=. then dm_control=.; else dm_control=1;
end;
do i=1 to 3;
if Scan( diag{i},1,'.') in ("E10", "E11", "E13") then diag_control=1; else diag_control=0;
end;
run;

 

Reeza
Super User
Drop the else, otherwise it will always get reset to 0.
Reeza
Super User

Use the colon operator.

 

if diag{i} in: ("E10", "E11", "E13") then diag_control=1;
else diag_control=0;

@RebeccaB_ wrote:

Hi, 

 

I'm trying to flag all individuals with diagnosis codes E10, E11, and E13. The problem is, I would like this to include all values for that overarching diagnosis code. So for example, if there are diagnosis codes E11.17, E11.21, E11.34, E10.22, E13.49, I would like to flag any with E10, E11, or E13 to be flagged. My code is below and thanks in advance for any help! 

 

data work.diabetes_control_num;
set work.diabetes_control;
array diag{3} $ diagnosis_1 diagnosis_2 diangosis_3;
array a1c_last{1} a1c2;
do i= 1 to 1;
if a1c_last{i} >= 9 then dm_control=0; else if a1c_last{i}=. then dm_control=.; else dm_control=1;
end;
do i=1 to 3;
if diag{i} = in ("E10", "E11", "E13") then diag_control=1; else diag_control=0;
end;
run;


 

ballardw
Super User

@Reeza wrote:

Use the colon operator.

 

if diag{i} in: ("E10", "E11", "E13") then diag_control=1;
else diag_control=0;

@RebeccaB_ wrote:

Hi, 

 

I'm trying to flag all individuals with diagnosis codes E10, E11, and E13. The problem is, I would like this to include all values for that overarching diagnosis code. So for example, if there are diagnosis codes E11.17, E11.21, E11.34, E10.22, E13.49, I would like to flag any with E10, E11, or E13 to be flagged. My code is below and thanks in advance for any help! 

 

data work.diabetes_control_num;
set work.diabetes_control;
array diag{3} $ diagnosis_1 diagnosis_2 diangosis_3;
array a1c_last{1} a1c2;
do i= 1 to 1;
if a1c_last{i} >= 9 then dm_control=0; else if a1c_last{i}=. then dm_control=.; else dm_control=1;
end;
do i=1 to 3;
if diag{i} = in ("E10", "E11", "E13") then diag_control=1; else diag_control=0;
end;
run;


 


Might be an issue if codes of E100, E110 or E130 exist. May not be an issue but there are just so blinking many ICD codes out there ...

Reeza
Super User
True, but you could also just add the periods to the end in that case but it really depends on the coding. In a perfect world you have a lookup table that has the code in a hierarchical fashion you can just filter out.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 6 replies
  • 897 views
  • 3 likes
  • 3 in conversation