Desktop productivity for business analysts and programmers

Reassigning Libnames

Reply
Frequent Contributor
Frequent Contributor
Posts: 76

Reassigning Libnames

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 clearSmiley Wink 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
Super Contributor
Posts: 260

Re: Reassigning Libnames

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
Occasional Contributor
Posts: 6

Reassigning Libnames

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

Ask a Question
Discussion stats
  • 2 replies
  • 146 views
  • 0 likes
  • 3 in conversation