They are an exact match.
The records being affected are only those records that don't include any of the 4 ICD 10 codes - they include other ICD 10 codes, just not those 4 specific codes.
Even though they don't contain those codes, I need to keep the records.
I was going to set the new variable CMDX = 0 at the start of the syntax where it's length and format are defined, but if I do that, it would compromise the statement "if missing (CMDX) then CMDX = dx(i);"
@SM1 wrote:
The records being affected are only those records that don't include any of the 4 ICD 10 codes - they include other ICD 10 codes, just not those 4 specific codes.
Even though they don't contain those codes, I need to keep the records.
All the observations should have the CMDX variable populated with onle of the four DX's because all observations contain at least one of these diagnoses.
I don't think there's anything in the code I provided that deletes records. It would be missing, or you can set it to any other variable you want, including the text 'Missing'. Also, this doesn't match what you stated earlier.
I added in some comments, hopefully it helps you to understand the code better.
data palms.FM01_DX;
set palms.fm01_ela;
*Initialize CMDX variable type and value;
length CMDX $8.;
format CMDX $8.;
CMDX='MISSING';
*Set array that holds codes you're looking for;
array find_dx(4) $ _temporary_ ('DOD0301', 'DOD0302', 'DOD0303',
'Z0289');
*Create array that is for diagnosis codes fields;
array dx(10)$ dx1-dx10;
*Loop over values you're searching for;
do i=1 to 4;
*If a diagnosis that matches a value of interest then assign it to the CMDX;
if whichc (find_dx(i), of dx(*))>0 then do;
if CMDX='MiSSING' then CMDX = dx(i);
end;
end;
run;
Thank you for all the suggestions.
I don't lose the observations so long as I remove the statement "output;"
Thanks again for your help!
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!
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.