The error is because your SQL query got no hits and so it did not create the macro variable.
You could code for that by setting some default value into the macro variable before the query. Or you could define the macro variable as LOCAL will insure that it exists.
If the cause was that your supplied values did not match the case of the data then you could update the macro slightly so that users do not need to provide exact case of text that you are searching for,
%macro flag(codetype, flagtype);
%local codelist;
proc sql;
select quote(trim(code))
into :codelist separated by ' '
from CODES
where upcase(codetype)=%upcaase("&codetype")
and upcase(flagtype)=%upcase("&flagtype")
;
quit;
data CLAIMS;
set CLAIMS;
if &codetype.1 in (&codelist) then _&flagtype=1;
run;
%mend flag;
... View more