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

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: 

 

  1. 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? 
  2. Is there a difference between deleting a library and cancelling its libref? ( eg. libname libref clear; )

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 !

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

7 REPLIES 7
Reeza
Super User

@Masande wrote:
  1. 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: 

  1. 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? 
  2. 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. 


 

Masande
Fluorite | Level 6

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:

 

  1. Why does deleting a lib then creating it again will keep the relation between the libref and the data set ? Where is this link stored ?

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. 

 

Reeza
Super User
Libref names are arbitrary, it’s the path that matters. The path is what tells you where the file is stored since SAS creates the physical copy there. You can navigate to that location on your computer and see the files.

When you declare a library with same path as another the log tells you this as well. Not sure what will happen with your code, test it and let us know. Always read the log.
Reeza
Super User
A library is a physical collection, the data sets exist as files in the file path.
ballardw
Super User

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.

SuryaKiran
Meteorite | Level 14

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.

Thanks,
Suryakiran
Masande
Fluorite | Level 6

Thank your for your answers. I understand how librairies work now! 

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!

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
  • 7 replies
  • 1842 views
  • 4 likes
  • 4 in conversation