Macro variable &SUB does not exist. You also need two semi-colons on this line:
%if &sub ne %then by &byvar;;
One ends the %IF and one ends the BY
From now on, if you hare having problems with MACRO code, please use
options mprint symbogen mlogic;
at the start of your program.
From now on, do not show us parts of the log disconnected from the code. Show us the LOG from PROC MIXED (or whatever PROC you are using) including the code and ERRORs/WARNINGs in the order they appear in the LOG, without modification, and without you selecting certain parts of the log of PROC MIXED (or whatever PROC you are using) to show us and not showing us other parts.
--
Paige Miller