Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using LET variable in INCLUDE command in SAS?

Tags:

sas

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!

[Edit] Answer

I was missing the ';' at the end of the %INCLUDE statement. =/

like image 210
Matt Klein Avatar asked Jan 15 '23 13:01

Matt Klein


1 Answers

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.

like image 72
WojtusJ Avatar answered Jan 30 '23 02:01

WojtusJ