BookmarkSubscribeRSS Feed
pmaloney
Calcite | Level 5

I have a large ED visit dataset with 32 variables for potential ICD10 codes. I am trying to determine agricultural injuries which will be identified with either a single ICD10 code, or combinations of 2 ICD10 codes. Identifying cases by the single codes is easy as I've just set those up with the following do loop:

 

farminj=0;
array DX $ dxp diag1-diag25 ECode1-Ecode6;
do i =1 to 32;
if DX in: ('various single ICD10 codes') then farminj=1;
end;

What I'm not sure about is how to set up a search which tests for combinations of ICD10 codes. Here is a list of 4 example combinations: 

W5511 + Y9271

W5512 + Y9271

W5512 + Y9272

Y9271 + Y93K3

 

These codes could be in any of the 32 variable positions, and the order is not always consistent between the two codes. So in one case you could have something like [diag1=Y9271 diag7=W511] and in another case you could have [diag2=W512 diag5=Y9271] and I would want both of those cases to be flagged with farminj=1.

 

I feel like there must be some sort of nested do loop I can do which will make this work, but I haven't had much luck figuring out how to write that. 

 

Thanks for any help! (SAS Enterprise Guide 8.2)

1 REPLY 1
ballardw
Super User

One way is to search using the WHICHC, or WHICHN for numeric values, with the array. The WHICHC function returns the position the value is first found in a list of values or 0 if not found. So if you get a zero result there isn't a match.

It also doesn't require comparing each value, so might simplify your current "loop" approach.

 

For one combination

If whichc('W5511', of DX(*)>0 and whichc('Y9271',of DX(*))>0 then <this is one of the combinations and do what you will>;

( ) around each comparison and an "or" between comparisons would probably be the easiest for multiple comparisons.

 

If you are only providing one flag variable you could also check to see if it that has already been set. If it has then no need to even do the check.

 

If your list of values was "nice" as in sequential or comparing all of the first values with all of the second values then this could be accomplished with some iterated do loops but that does not seem to be the case here.

 

Your example code wouldn't quite run. You would have to have something more like (still not quite valid) but needs the loop index with the array.

farminj=0;
array DX $ dxp diag1-diag25 ECode1-Ecode6;
do i =1 to 32;
   if DX[i] in: ('various single ICD10 codes') then farminj=1;
end;

 This does compare every value in the array with the codes. If you have a large data set that adds up for time. You might consider:

farminj=0;
array DX $ dxp diag1-diag25 ECode1-Ecode6;
do i =1 to 32;
   if DX[i] in: ('various single ICD10 codes') then do;
       farminj=1;
       leave;
   end;
end;

Which will exit the do loop at the time the first match is found and the Farming value is set to 1.

 

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!

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
  • 1 reply
  • 463 views
  • 0 likes
  • 2 in conversation