According to the SAS Certification Prep. Guide:
When you delete a SAS library, the pointer to the library is deleted, and SAS no longer has access to the library. However, the contents of the library still exist in your operating environment.
I have two questions about this statement:
The library manipulations are not clear in my mind and I can't really conceptualize these notions. I think that solving these two points could help me to better understand them.
Thank you !
The basic idea is that a LIBREF links to your computers file system.
When you assign a libref to a folder that has SAS data files and such then SAS runs a number of tasks in the background. Some of them are reading the data stored in the data set to know things kept in the data set header information such as the names and properties of the variables and the number of observations.
There are a number of data views in the SASHELP library, most of them start with the letter V, that store all that metadata.
Vtables has detailed information about tables (data sets and views); Vmember has simplier list of dataset names and their libraries and file path; Vcolumn has information about the variables in the data sets and which library.dataset they are in. Other views contain the data about libraries, system options, macro definitions, macro variables, formats, titles and footnotes and much more. Explore.
For extra added fun you library has an engine, the way items are used, associated with the definition. If you have SAS datasets from significantly different versions of SAS such as V6 and V9 you can assign the library to only recognize one of the versions. Libraries may also span multiple folders. The SASHELP library is the most common one to do so but I have used this feature when inheriting somewhat scattered data that made more sense in a single library (at least for some operations). Look in SASHELP.VSLIB to see library path definitions.
Generally your libraries have few enough members that the time spent reading the header information will occur without you knowing it. But the more libraries, datasets, views, catalogs involved you can notice performance issues referencing these data views.
@Masande wrote:
2. What would happen in the following case ?
libname lib1 "/folders/myfolders/"; libname lib2 "/folders/myfolders/"; proc copy in = lib1 out = lib2; select ds1; libname lib2 clear;
Both lib being in the same folder and the proc step trying to copy the dataset in the same folder location.
Run the code and see. Though I would recommend and tests for odd file manipulations be tested using libraries with out critical data just in case.
@Masande wrote:
- What does "the contents of the library still exist in your operating environment" mean in a real situation? What am I suppose to see in SAS Studio and why is their existence important?
You can consider a library a pointer to a folder or file. In most cases it's a folder with SAS data sets, but you can also create libname statements to a single file.
I have two questions about this statement:
- What does "the contents of the library still exist in your operating environment" mean in a real situation? What am I suppose to see in SAS Studio and why is their existence important?
- Is there a difference between deleting a library and cancelling its libref? ( eg. libname libref clear; )
In this context, there is no difference.
Deleting a library could technically mean that you delete the files, but I don't think that's how most people use the term.
Thank you for your answer.
About its first part: does it mean that the library is a logical/non-physical collection of datasets and, if you create some datasets into the lib before deleting it, the datasets will stay but you can't reach/use them anymore with libref.dataset until a new libref poiting towards the folder?
In this case, I've got two additional questions:
For instance:
libname lib2 "/folders/myfolders/";
proc copy in = lib1 out = lib2;
select ds1;
libname lib2 clear;
If I create lib2 again, the ds1 copy will stay in "the new" lib2. Where does SAS find the relation between them, even after a session reset ?
2. What would happen in the following case ?
libname lib1 "/folders/myfolders/";
libname lib2 "/folders/myfolders/";
proc copy in = lib1 out = lib2;
select ds1;
libname lib2 clear;
Both lib being in the same folder and the proc step trying to copy the dataset in the same folder location.
The basic idea is that a LIBREF links to your computers file system.
When you assign a libref to a folder that has SAS data files and such then SAS runs a number of tasks in the background. Some of them are reading the data stored in the data set to know things kept in the data set header information such as the names and properties of the variables and the number of observations.
There are a number of data views in the SASHELP library, most of them start with the letter V, that store all that metadata.
Vtables has detailed information about tables (data sets and views); Vmember has simplier list of dataset names and their libraries and file path; Vcolumn has information about the variables in the data sets and which library.dataset they are in. Other views contain the data about libraries, system options, macro definitions, macro variables, formats, titles and footnotes and much more. Explore.
For extra added fun you library has an engine, the way items are used, associated with the definition. If you have SAS datasets from significantly different versions of SAS such as V6 and V9 you can assign the library to only recognize one of the versions. Libraries may also span multiple folders. The SASHELP library is the most common one to do so but I have used this feature when inheriting somewhat scattered data that made more sense in a single library (at least for some operations). Look in SASHELP.VSLIB to see library path definitions.
Generally your libraries have few enough members that the time spent reading the header information will occur without you knowing it. But the more libraries, datasets, views, catalogs involved you can notice performance issues referencing these data views.
@Masande wrote:
2. What would happen in the following case ?
libname lib1 "/folders/myfolders/"; libname lib2 "/folders/myfolders/"; proc copy in = lib1 out = lib2; select ds1; libname lib2 clear;
Both lib being in the same folder and the proc step trying to copy the dataset in the same folder location.
Run the code and see. Though I would recommend and tests for odd file manipulations be tested using libraries with out critical data just in case.
Yes, the term "deleting SAS Libraries" might cause confusing. "Disconnecting" might be the proper term here.
This will remove 'mylib' under libraries, but doesn't physically delete any files that pointing to that library.
LIBNAME mylib CLEAR;
Where as, the below code still shows the library but physically deletes all the datasets.
proc datasets lib=mylib kill;
run;
I rather prefer to say disconnect the library, instead of the term 'delete' which might confuse some users.
Thank your for your answers. I understand how librairies work now!
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.