BookmarkSubscribeRSS Feed
ubiq
Fluorite | Level 6

Hello everyone, I hope you all are doing great. 

 

I'm having trouble with some macros. 

 

/*Using % at the start and () at the end just to point out the name between is a macro*/

I wrote %macro_var() which I already tested and works without issues. I exported %macro_var() to a folder I intend to use as an autocall library. The code is in a normal .sas file.

 

Then I got %macro_other() which calls %macro_var() to resolve some variables. %macro_var() pretty much creates some variables I use in %macro_other(). I separated the code in another macro because together is just a huge macro that is difficult to read and keep developing.

I cannot post all the code nor can I actually post the original code due to company policies, but it looks structurally like this: 

 

%MACRO macro_other(param1=, param2=);

OPTIONS MAUTOSOURCE;

OPTIONS MPRINT SYMBOLGEN MLOGIC; /*I use this for me to debug better*/

FILENAME shortn "C:\containingFolder\folderWhereMyMacrosAre";

OPTIONS SASAUTOS=(shortn sasautos);

/*I know I could skip the periods at the end of vars but I keep them for my editor to recognize them and highlight them*/

%macro_var(mpar=&param1., mpar2=&param2.) 

/*I use the trim() as sanity check due to unexpected inserted spaces before the number*/

%DO i = 1 %TO %SYSFUNC(TRIM(&variable_macro_var_resolves));

/*

A lot more of code I cannot post :(, excuse me

*/

%MEND macro_other;

 

So the issue is that it seems it cannot resolve the reference to %macro_var(). %macro_var() has 2 parameters which are the same as %macro_other() but I changed their names in each macro for me to not get confused.

 

The log has this: 

/*Code before the WARNING*/

WARNING: Apparent invocation of macro MACRO_VAR not resolved.

NOTE: Line generated by the invoked macro "MACRO_OTHER".

152 OPTIONS MAUTOSOURCE; OPTIONS MPRINT SYMBOLGEN MLOGIC; FILENAME shortn "C:\containingFolder\folderWhereMyMacrosAre"; OPTIONS SASAUTOS=(shortn sasautos); %macro_var(mpar=&param1., mpar2=&param2.) 

 

ERROR 180-322: Statement is not valid or it is used out of proper order.

/*The 180 with a line on it is exactly under the start of %macro_var(), right at the '%'*/

/*SYMBOLGEN stuff here*/

WARNING: Apparent symbolic reference VARIABLE_MACRO_VAR_RESOLVES not resolved.

WARNING: Apparent symbolic reference VARIABLE_MACRO_VAR_RESOLVES not resolved.

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 

%SYSFUNC(TRIM(&variable_macro_var_resolves))

ERROR: The %TO value of the %DO I loop is invalid. 

ERROR: The macro OTHER_MACRO will stop executing.

 

So, at first I thought perhaps the macro I'm trying to call is wrong but I have already throughly tested it and checked everything. It does what it's intended to on its own, so I discarded that the ERROR sentences at the end of the log are any relevant for now. I think it's all in the resolution. Worst of all of this is that when I print the autocall libraries of my session they do have the folder I declare at the start of the macro. 

Also I thought it could perhaps be a privileges issue but it isn't. The folder hosting my macros is accessible to SAS. 

 

I already read most of previous posts with similar circumstances but I cannot find any answer. I learnt SAS pretty much by reading books from SAS and I did the SASAUTOS part as the book. I still am unsure if it should be outside the macro or within of it. No one in my team or teams close to mine has any idea of SAS programming nor does the IT dept. I'm pretty much alone on this and would appreciate a lot any advice and help. 

 

Again, excuse me for not be able to post the entire code, changed the names and posting just a section of the log. It's that policies are extremely strict regarding code around stuff I build where I work at. 

 

Thank you very much for any help! It means the world to me!

--

ubiq

--
ubiq
15 REPLIES 15
Sajid01
Meteorite | Level 14

Hello
Where has the macro variable &variable_macro_var_resolves  been defined?
Is it global or local? 
The answer to these questions should resolve your issue.

ubiq
Fluorite | Level 6

&variable_macro_var_resolves is defined/created in %macro_var(). It's defined as a global variable. If it helps, %macro_var() more or less looks like this at the start: 

 

%MACRO macro_var(mpar=, mpar2=);

OPTIONS SYMBOLGEN;

%GLOBAL variable_macro_var_resolves other_variable another_variable;

/*

PROC SQL stuff creating the variables and some other code

*/ 

%MEND macro_var;

 

Thanks a lot for your quick reply!

--
ubiq
Tom
Super User Tom
Super User

So make sure you run that code so that %MACRO_VAR() is defined BEFORE you call %MACRO_OTHER().

Tom
Super User Tom
Super User

So you are showing the definition of the macro %MACRO_OTHER() but you have not shown the definition of the macro named %MACRO_VAR() that it is calling.  The error message is saying you haven't defined that macro yet.

 

Where is the definition of that macro?

ubiq
Fluorite | Level 6

The %macro_var() definition is in another program in the same project. I haven't run it in the current session (therefore it's not compiled/at disposal of SAS within the session/project, right?) because I need to test how to use autocall libraries. The %macro_var() program was exported to the "C:\containingFolder\folderWhereMyMacrosAre" directory which I'm trying to use as an autocall library. The macro file has the same name I use in the %macro_other() when calling it and it is inside a .sas file. 

 

Thanks a lot in advance for your help!

--
ubiq
Tom
Super User Tom
Super User

Make sure you can see the files in the path you are using for your sasautos search location.

 

Also make sure to set the MRECALL option so that even if it failed to find %MACRO_VAR() before it will look for it again the next time you reference it.

ubiq
Fluorite | Level 6

Thanks. Just put the option MRECALL, submitted the code and it's still not working 😞 

 

Thanks a lot for your help so far! 

 

--
ubiq
Tom
Super User Tom
Super User

Start small.

Set the SASAUTOS paths and other options.

Call the subroutine macro that you are having trouble finding.

If it works then start making your program more complex.

 

If it does not work then figure out why.

Is the file actually there? Try to %INCLDUE the file?  Is it found?  Is the macro compiled? Can you call it now?

 

Say the path you want SAS to use to find your autocall source code is in the macro variable PATH.  Your test code might be:

%let path= my folder with autocall source code ;
options sasautos=("&path" sasautos) mautosource mrecall ;
* call the macro;
%mymacro();
* compile the macro manually ;
%include "&path/mymacro.sas" / source2;
%mymacro();
Astounding
PROC Star

These statements are misplaced:

FILENAME shortn "C:\containingFolder\folderWhereMyMacrosAre";

OPTIONS SASAUTOS=(shortn sasautos);

They appear inside a macro definition, so they don't execute and tell SAS where to look, until you run a macro.  But SAS can't find the macros because the FILENAME statement has not yet executed.

 

Put those statements outside all macros.

ubiq
Fluorite | Level 6

Oh, thanks, didn't know that! Should I submit from a different macro/put it in the code submitted before anything else runs? 

 

Thanks you a lot for your input!

--
ubiq
Astounding
PROC Star

Just keep it at the top of your program, outside of any macros.

ubiq
Fluorite | Level 6

Ok ok. Just did that! 

 

Thanks!

--
ubiq
Sajid01
Meteorite | Level 14

Wondering if your problem is resolved?

ubiq
Fluorite | Level 6
Nope, unfortunately the issue persisted; haven't tried the %INCLUDE (I've been busy and didn't check back here, but thanks for asking!), my last hope (or the compiled macro facility); for now, I had to merge the code in a single huge program to show the functionality to my team. TG I used git so no issue to merge them for now, but since this solution still has more macros to be written, I want to be as tidy as possible from the first "release".
--
ubiq

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 15 replies
  • 922 views
  • 2 likes
  • 4 in conversation