Hello,
I'm trying to invoke a macro from my code but I keep getting this error:
WARNING:Apparent invocation of macro TEST not resolved.
ERROR 180-322: Statement is not valid or it is used out of proper order.
This is the code that I'm calling the macro from:
Options
Mautosource
Sasautos = ('unix link where the test.sas file is located')
source2
nocenter mlogic symbolgen
;
%test(table.acct,acct);
when I copy paste the entire macro in the code, it runs fine. which confirms there is nothing wrong with the macro. Below is the macro definition in the file test.sas:
%macro test(table,var);
proc sql noprint;
CONNECT TO teradata (user= "%sysget(user)" password = "&pass" tdpid="rchtera" mode=teradata);
create table abc as select * from connection to teradata
( select top 2 &var. from &table.);
disconnect from teradata;
quit;
%mend;
I even tried using %include, but that hasn't helped either. In any case I would prefer invoking without using %include.
Appreciate any help!
When you add a path into the SASAUTOS option and then ask to run a macro named TEST it will look for a file name 'test.sas' in that location.
So what happens when you try:
%include 'unix link where the test.sas file is located/test.sas' ;
%test(table.acct,acct);
Unix can do strange things also. Someone had an issue on this forum a little while ago because the actual name of the file ended in a space.
What happens when you try to %include the file? Does it not see test.sas?
Remember that on unix your file paths/names are case sensitive. Also double check that your link is working. Yet another possibility is that the account used to run the SAS job does not have read access to test.sas.
Also, within a SAS session SAS will only look for an autocall macro definition once, by default. So once you see that message, it will not look again for the definition. When debugging, it's sometimes helpful to change that by setting the system option MRECALL.
I checked the link, no issues there with the access. There is no inconsistency in the name of the file either, the case and spelling match.
I tried include like this:
filename job "unix link where test.sas is located";
%include job(test);
This is what I get in logs:
WARNING: Physical file does not exist, /unix link/test.sas.
ERROR: Cannot %INCLUDE member test in the aggregate JOB.
@AJ_Brien wrote:
I checked the link, no issues there with the access. There is no inconsistency in the name of the file either, the case and spelling match.
I tried include like this:
filename job "unix link where test.sas is located";
%include job(test);
This is what I get in logs:
WARNING: Physical file does not exist, /unix link/test.sas.
ERROR: Cannot %INCLUDE member test in the aggregate JOB.
What happens when you don't use a filename reference at all? If it can't find that path/program then it won't run.
%include ' path to .sas file here';
I get this:
ERROR: Invalid file, 'path to .sas file'.
ERROR: Cannot open %INCLUDE file 'path to .sas file'.
But I queried a dataset that exists in that same link and was able to see that without any problem. So I definitely do not have any access issues and that path is definitely correct.
When you add a path into the SASAUTOS option and then ask to run a macro named TEST it will look for a file name 'test.sas' in that location.
So what happens when you try:
%include 'unix link where the test.sas file is located/test.sas' ;
%test(table.acct,acct);
Unix can do strange things also. Someone had an issue on this forum a little while ago because the actual name of the file ended in a space.
This worked!
Could you please explain why did I have to use the include with the macro invocation? I've never seen anyone do that before?
@AJ_Brien wrote:
This worked!
Could you please explain why did I have to use the include with the macro invocation? I've never seen anyone do that before?
When the %include is successful, assuming there is actual SAS code in the file, then that code is submitted for execution. In this case that likely means the macro was finally compiled.
The log likely had a note to that affect.
Then the issue is the MRECALL option as previously mentioned.
Perhaps your autoexec or some earlier code in the same SAS session already used that macro name and so SAS thinks it shouldn't have to look for the source again.
The MRECALL option is what tells it to try again.
And the name of the file you included was literally test.sas and not something with one or more uppercase letters? Like TEST.SAS or Test.SAS?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.