You could switch to arrays, as suggested. Then you wouldn't need any macro language at all. However, you can get macro language to do the job easily enough by cutting out a couple of percent signs:
%macro abc;
data want;
set have;
%do num=1 %to 25;
if diag_code&num. in ("Z590", "Z591", "Z598") then
dcheck&num.=1;
%end;
run;
%mend;
%abc
The idea is to have the DATA step process the data. The role of macro language is to make sure that the correct DATA step code gets generated.