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;
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?
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?
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: 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!