DATA Step, Macro, Functions and more

Error with Macro library

Not applicable
Posts: 0

Error with Macro library

I am running a macro with following syntax for options,

Dm 'log;clear;output;clear;';
LIBNAME XYZZZ 'U:\0xxx Protocol\xxxx_Completedata_XYZZ';
LIBNAME LIBRARY 'C:\Users\rmalapati\Documents\My SAS Files\Sangamo_SB_509_0801\0801 Protocol\formats';
options linesize=200 pagesize=100;
libname macros 'U:\Macros';
options mprint mlogic mstored sasmstore=macros;
options linesize=256 pagesize=100;
ods listing;

The following error gets displayed after running the sas for second time, but when running on a new sas sesison with the same syntax the error cant be seen.

I know why the error is being displayed but am not able to get the right solution

"ERROR: Unable to clear or re-assign the library MACROS because it is still in use.
ERROR: Error in the LIBNAME statement."

How to get around this?
Super Contributor
Super Contributor
Posts: 366

Re: Error with Macro library

Posted in reply to deleted_user

Simply move the line
libname macros 'U:\Macros';
to the top and second (third, etc. ) time
submit a block of code not including this line.

Super User
Posts: 10,761

Re: Error with Macro library

Posted in reply to deleted_user
Or . You need one more statement to release your libname.

libname macros clear;

SAS Employee
Posts: 58

Re: Error with Macro library

Posted in reply to deleted_user
This won't help you now, but when 9.3 comes out, it will have a
%SYSMSTORECLEAR statement that will close the current library and clear the libref.
Occasional Contributor
Posts: 6

Error with Macro library

Posted in reply to deleted_user

I haven't found an elegant solution, but I'm using this code in Enterprise Guide:

*-- start code --;

data _NULL_;

  length WORD $8;

     do j = 1 to 8;

        WORD = byte(int(65 + ranuni(0)*26)) || WORD;


     call symput("mylibrary", WORD);


libname &mylibrary 'physical_path_to_library';

*-- end code --;

This assign every time a different random LIBREF to you library.

It works.



Valued Guide
Posts: 2,191

Error with Macro library

without the data step code, you can assign a "random" libref like

libname A%scan( %sysfunc( ranuni(0), 9.7 ),2,.) 'physical path to library' ;

it creates a libref that is unlikely to repeat having a random 7 digit number following that A.

I just tested it and it even works within a %sysfunc( repeat( ,4 )) where it happily assigned 5 unique libnames (all with the same path)

%sysfunc( repeat( %nrstr(

libname A %%scan( %%sysfunc( ranuni(0), 9.7 ), 2, . ) 'my path' ;

), 4 ) ) ;

The reason the macros libname won't release is its use in option sasmstore=macros ;

I'm not sure you can release the sasmstore assignment. (nor sure I would want to release it)

Use Scott's approach - not performing the assignment of the macros libname after the first run. Place "one-time-only" code in the autoexec.



Ask a Question
Discussion stats
  • 5 replies
  • 6 in conversation