BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hnb_matt_d
Obsidian | Level 7

Hoping everyone is well today.  

 

Due to a recent job change, I have inherited code that has passed through a number of prior colleagues, and I'm currently trying to clean it up as time permits.  I found today code that actually clears librefs, and it started me wondering why that would be done and if there's an advantage or a reason I should either continue in certain scenarios or not worry about it.  

 

This code in which I found the libname clear statement does create a temporary custom library, so it seems to be logical (in my mind, anyway).  Most of the code I write creates libraries directly out of system databases (read only access), so I wasn't sure if clearing libnames is necessary or advisable.  

 

Thanks in advance!  

 

Matt D

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Sometimes programmers use the same name to reference a library but it's a different location. For example, we have a specific folder structure for our projects so I often have a 'results' library in programs to output final results as well as a 'raw' library to store inputs. For each project these are actually different folders in the file structure. But the library names are the same in many programs so in this case it's definitely good to clear them in case something goes awry!

 


@hnb_matt_d wrote:

Hoping everyone is well today.  

 

Due to a recent job change, I have inherited code that has passed through a number of prior colleagues, and I'm currently trying to clean it up as time permits.  I found today code that actually clears librefs, and it started me wondering why that would be done and if there's an advantage or a reason I should either continue in certain scenarios or not worry about it.  

 

This code in which I found the libname clear statement does create a temporary custom library, so it seems to be logical (in my mind, anyway).  Most of the code I write creates libraries directly out of system databases (read only access), so I wasn't sure if clearing libnames is necessary or advisable.  

 

Thanks in advance!  

 

Matt D


 

View solution in original post

3 REPLIES 3
Reeza
Super User

Sometimes programmers use the same name to reference a library but it's a different location. For example, we have a specific folder structure for our projects so I often have a 'results' library in programs to output final results as well as a 'raw' library to store inputs. For each project these are actually different folders in the file structure. But the library names are the same in many programs so in this case it's definitely good to clear them in case something goes awry!

 


@hnb_matt_d wrote:

Hoping everyone is well today.  

 

Due to a recent job change, I have inherited code that has passed through a number of prior colleagues, and I'm currently trying to clean it up as time permits.  I found today code that actually clears librefs, and it started me wondering why that would be done and if there's an advantage or a reason I should either continue in certain scenarios or not worry about it.  

 

This code in which I found the libname clear statement does create a temporary custom library, so it seems to be logical (in my mind, anyway).  Most of the code I write creates libraries directly out of system databases (read only access), so I wasn't sure if clearing libnames is necessary or advisable.  

 

Thanks in advance!  

 

Matt D


 

hnb_matt_d
Obsidian | Level 7
Thanks, Reeza! Makes sense now!
SASKiwi
PROC Star

Whether you clear or don't clear SAS libraries in your SAS programs depends on a variety of factors. If these programs are using SAS libraries that are shared across many SAS users, then normally these would be set up automatically when you start SAS and there would be no need to clear them once you have finished with them. On the other hand if the SAS library is specific to the program then it does make sense to clear it after use.

 

I'd also make the point that if you are running SAS programs on a regular basis like once a day or week or month then you should be scheduling these using a scheduling tool and running the programs in batch mode. In this case clearing LIBNAMEs doesn't make a lot of sense as they will be lost when the program finishes anyway. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1442 views
  • 4 likes
  • 3 in conversation