Assuming that you don't need COUNT_DIAG for any other purpose, just simplify the program. If you simplify it enough, running the program would be just as easy as calling a macro. For example:
proc sql;
select count(distinct(diag_2)) into : k from drugs;
quit;
With no macro defined, you won't have any difficulty using &K, and the program will likely be easier to understand.
... View more