I'm trying to organize my SAS code by defining a macro variable called root. Then, I want to be able to have all of my %INCLUDE
statements use the &root
value so I can just define the %INCLUDE
in terms of the root:
%LET root = C:\Documents and Settings\me\Desktop\mine\SAS;
%include "&root\lib\work.sas"
However, when trying to run this under SAS 9.2 I get the following error from the log:
1 %LET root = C:\Documents and Settings\me\Desktop\mine\SAS;
ERROR: Incorrect %INCLUDE statement will not be executed. There is a syntax error.
2 %include "&root\lib\work.sas"
So it looks likes the &root
variable isn't being expanded into its value in the %INCLUDE
statement. What am I doing wrong?
Thanks!
I was missing the ';'
at the end of the %INCLUDE
statement. =/
In that situation you probably need to use the separator, that marks the end of a macro variable name, which is ".", so your code will look like:
%LET root = C:\Documents and Settings\me\Desktop\mine\SAS;
%include "&root.\lib\work.sas"
This is actually needed only when variable name "touches" something, but I would recommend using it ALWAYS - it's a good practise. Also when there is a dot after the variable name you should put "that" dot, so there will be two dots, like:
%LET root = C:\Documents and Settings\me\Desktop\mine\SAS;
%LET fname = work;
%include "&root.\lib\&fname..sas"
EDIT
As @Joe correctly states in other answer, the real problem in that situation is a lack of semicolon after %INCLUDE statement. Placing it after the path should solve the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With