Solution to an immediate problem
You need to wrap the macros in double quotes if you want the SAS to treat them as string constants. Otherwise, it will process them just like any other random bits of text that it finds in your data step.
Alternatively, you can override macros to include quotes.
As an additional feature, you can use the symget or resolve functions, but they are usually not needed if you do not want to create macro variables and use them again at the same data step. If you use them as a substitute for double quotes, they tend to use a lot more CPUs, since by default they evaluate macro vars once per line - usually macro vars are evaluated only once at compile time before your code done.
The best approach?
For what you are doing, you donโt need to use a dataset at all - you can instead define a custom format that gives you much more flexibility in how you can use it. For instance. this creates a lookup format:
proc format; value lookup 1 = 'A' 2 = 'B' 3 = 'C' other = '#N/A' ; run;
Then you can use this format:
%let testvar = 1; %let testvar_lookup = %sysfunc(putn(&testvar, lookup.));
Or in the data step:
data _null_; var1 = 1; format var1 lookup.; put var1=; run;
source share