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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2076 views
  • 0 likes
  • 3 in conversation