To encapsulate this program in a macro, suitable for 3 data sets, you need to overcome a couple of problems.
First, the output data set name is ci. That's fine when you have one data set to process. But if you process three data sets, each run replaces ci with a different output. You will need 3 data set names, not 1.
Second, the code itself could use a little bit if cleaning up. In particular:
SUBSTR is inefficient
Continuing to search all 25 variables is inefficient once you already have a single match that sets DMCAT to 1.
Try it this way:
%macro set_dmcat (dsn);
data ci_&dsn;
set &dsn;
array icd_dx_cd_ {25}; /* autoatically uses the array name plus a numeric suffix */
dmcat=0;
do i=1 to 25 until (dmcat=1);
if icd_dx_cd_{i} in: ('E08', 'E09', 'E10', 'E11', 'E13') then dmcat=1;
end;
run; %mend set_dmcat; %set_dmcat (x) %set_dmcat (y) %set_dmcat (z)
Using =: compares whether two strings are equal, but makes the comparison using the number of characters in the shorter string. That lets you eliminate SUBSTR when you want to examine the beginning of a string.
Adding the UNTIL condition lets you stop examining the rest of the diagnosis codes once a match has been found.
... View more