I am using folowing:
%LET compile_macros = N;
libname optmacro "C:\Codes\Macros";
options mstored sasmstore=optmacro;
(...)
%IF &compile_macros. = Y %then %do;
%include "&location.\Codes\02_ Macro - Prediction.sas";
(...)
And 02_ Macro - Prediction.sas contains a macro named: macro grade_prediction /store;
Each time I open a new session, in the first run when compile_macros = Y/N, the run is success without any error, but from the second run onwards, I am getting following errors:
ERROR: Unable to clear or re-assign the library OPTMACRO because it is still in use.
ERROR: Error in the LIBNAME statement.
I am unable to re-assign the library and without it I don't know how to direct SAS to saved/compiled MACROS.
I tried 'libname optmacro CLEAR;' before assignment but to no avail.
Any idea how can I correct these error?
Thanks a lot in advance.
I have not used compiled macros for a long time and i recommend not to use them at all, as they can cause serious trouble. The error message is afaik caused by
options sasmstore=optmacro;
So resetting sasmstore should solve the issue.
options SASMSTORE='';
You didn't include the "&location.\Codes\02_ Macro - Prediction.sas" ode, so I can
t be 100% sure, but it looks like you are compiling your macros to a permanent library using code similar to this:
libname OPTMACRO "some location";
options mstored sasmstore=OPTMACRO;
%macro MyMacro1 /stored;
/*...more macro code...*/
%mend;
%macro MyMacro2 /stored;
/*...more macro code...*/
%mend;
/* And after the macro definitions: */
libname OPTMACRO clear;
You'll get the "ERROR: Unable to clear or re-assign the library OPTMACRO because it is still in use" message because SAS is still using the SASMACR catalog in the OPTMACRO library for compiled macro storage. Inserting a %sysmstoreclear macro statement just before trying to clear the OPTMACRO libref should do the trick - something like this:
%sysmstoreclear;
libname OPTMACRO clear;
May the SAS be with you!
Mark
Save yourself the hassle of compiled macros and use the autocall facility.
Also see Maxims 26 & 27.
Thank you very much for the tip. I'll try SASAUTOS now.
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.