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

Hello, I am using SAS 9.4 and I have a dataset with secondary diagnosis ICD10 codes. There are up to 120 secondary diagnosis codes listed. My goal is to build an array for the diagnosis codes and create a flag for any secondary diagnosis with a mention of alcohol. All the alcohol diagnosis codes start with an 'F10___' but depending on the specifics the code could be 3 more digits and there are too many ICD10 codes to just manually type out. I am trying to write a code to flag the observations with an alcohol related code associated to it by creating an array then doing a do loop that will select a partial string from the 120 variable array. I am not getting an error but my results come back as 0 observations which I know is incorrect based on spot checking one of the secondary code variables. Below is the code I am working with. 

 

data cancer3;
set cancer;
array CDiagcode {1:120} DX1-DX120; *build array of DX codes;
 do j = 1 to 120;                 
      if CDiagcode {j} = FIND(of CDiagcode{j}, 'F10') then do;
   *if secondary diagnosis is for alcohol*;
            substance10 = 1;
            SFlag = 1;                     *flag 2;
      end;
      else if SFlag not in (1) then do; *if no alcohol diagnosis DM = 0;
            substance10 = 0;
            SFlag = 0;                     *flag 3;
      end;
 end;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
At first glance, this line is wrong:

if CDiagcode {j} = FIND(of CDiagcode{j}, 'F10') then do;

The code will never match the results from the FIND, which returns a number and your array is likely text values. I'm guessing your log has a ton of errors or warnings? Can you post the log?

You likely want something similar to :

if cdiagcode(j) =: 'F10' then do;

View solution in original post

2 REPLIES 2
Reeza
Super User
At first glance, this line is wrong:

if CDiagcode {j} = FIND(of CDiagcode{j}, 'F10') then do;

The code will never match the results from the FIND, which returns a number and your array is likely text values. I'm guessing your log has a ton of errors or warnings? Can you post the log?

You likely want something similar to :

if cdiagcode(j) =: 'F10' then do;

tolsabeck
Calcite | Level 5

Thank you! The code I posted actually didn't result in any errors in the log. It just output the wrong answer. Adjusting it to your suggestion provided something that looks more correct. 

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!

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
  • 588 views
  • 0 likes
  • 2 in conversation