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
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
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
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.