BookmarkSubscribeRSS Feed
LAP
Quartz | Level 8 LAP
Quartz | Level 8
I am running macro in EG that reassigns the same libname at each iteration. At the end of the previous run I attempt to clear the libname (libname _project clear;) but get the following error.

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

Why? How do I circumvent this error?


Thanks
2 REPLIES 2
Olivier
Pyrite | Level 9
Hello.

My own experience of the problem (far from extensive) is related to having macro-programs stored in that library, in a catalog ; the library cannot be desassigned until the end of the SAS session.

As a circumvention : since you are iterating in your macro program, this sounds like you're using a macro loop. You can test the iteration number and only assign the library once (and desassign it once at the very end of your iterations) :

%DO loop_index = 1 %TO 1000 ;
%IF &loop_index = 1 %THEN %DO ;
LIBNAME _project "my library path" ;
%END ;
...
%IF &loop_index = 1000 %THEN %DO ;
LIBNAME _project CLEAR ;
%END ;
%END ;

Regards.
Olivier
pcavicch
Calcite | Level 5

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;

     end;

     call symput("mylibrary", WORD);

run;

libname &mylibrary 'physical_path_to_library';

*-- end code --;

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

It works.

Regards

Paolo

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 2 replies
  • 2146 views
  • 0 likes
  • 3 in conversation