In the situation that you decscribe (macro is producing correct code in the log but erroring at a valid statement), usually (always?) the problem is the macro language failed to unquote something. Macro quoting symbols are supposed to be automatically unquoted before they get to SAS compiler, and it they aren't, they can cause problems.
Since you are using %QSCAN, you are using macro quoting.
I would replace this part of your macro that returns SAS code:
&whitenedvar = &word - rho1 * LAG(&word);
with:
%unquote(&whitenedvar) = &word - rho1 * LAG(&word);
And see if that fixes it, or at least changes the error you get. It's possible &word will also need to be unquoted, so you could also try:
%unquote(&whitenedvar) = %unquote(&word) - rho1 * LAG(%unquote(&word));
... View more