Below is a response from SAS support on this. In short, & substitution will cause a rescan of the code, but % substitution will not. (I haven't found this difference documented anywhere, so this might be of general interest). "I have an answer for you regarding what is happening with the macro issue you raised with Leon. I simplified your example and added another statement to aid in the explanation. 1 %let B = b; 2 %macro A(); 3 a 4 %mend A; 5 6 data d; 7 bzz=2; 8 v2=&B.zz; 9 azz=1; 10 v1=%A()zz; __ 22 ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=. In the first instance (v2=&B.zz), the variable substitution operator & causes a rescan of the source starting at the point of the &. The rescan then sees the resultant text bzz as a single token and the Data Step compiler recognizes it as a known variable name. In the second instance (v1=%A()zz;), the generated text from the execution of %A does not cause a rescan. The generated “a”, is consumed by the Data Step compiler as the next token and it then sees the “zz” as a separate subsequent token. This causes the error. The %UNQUOTE causes a rescan which has the side effect of the “a” and “zz” getting merged into a single token and the Data Step compiler is happy. This is a subtle difference between using % and &. In this case, the & is the appropriate mechanism to use. Please let me know if you have any additional questions regarding this issue. Regards, Chris Warters
... View more