BookmarkSubscribeRSS Feed
thepushkarsingh
Quartz | Level 8

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. 

6 REPLIES 6
andreas_lds
Jade | Level 19

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='';
thepushkarsingh
Quartz | Level 8
I tried this but still same error. I can refrain from using compiled macros, will try autocall. Thanks for the tip.
SASJedi
SAS Super FREQ

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

 

 

Check out my Jedi SAS Tricks for SAS Users
thepushkarsingh
Quartz | Level 8
I think I am doing exactly like this, but after first run, in the same session all the subsequent runs still give the same error.
thepushkarsingh
Quartz | Level 8

Thank you very much for the tip. I'll try SASAUTOS now.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1343 views
  • 3 likes
  • 4 in conversation