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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1436 views
  • 0 likes
  • 3 in conversation