How to store your SAS dataset?
Some understanding about SAS data set
First of all, SAS data set in not an ASCII file, namely plain text file. So you cannot create/open it in "Notepad", "Word", or any kind of word processor. Instead, you would need special interface to manage it, e.g. SAS.
There are basically two types of data sets one will encounter in any SAS session. The first type is temporary, meaning the data set is ONLY referable within current session (before SAS application is closed). The second one is permanent, meaning that even the session (where the data set was created) is closed, the data set is still accessible for future attempt.
SAS dataset is structured in two main dimensions: variables (columns) and observations (rows). The variables in a SAS data set can include both characteristic and numeric variables. Beyond that one can also impose other information on the variables, e.g. label for variable names, customized format for variable contents, and another feature so called index.
How to store a SAS dataset permanently
Internally, SAS uses two-level naming scheme to manage all the data sets. The general form is "libref.dataset-name", where libref is the library reference that points to the physical path of data storage; and dataset-name is just the valid name (see rules below) you assign.
If one doesn't specify the libref when the data set is firstly created, SAS automatically assign "work" to be its libref. This libref will point to the working library whose content will be flushed once the current SAS session is closed.
To store a SAS data set permanently, upon its creation one will need to specify the libref that is defined beforehand. In campus lab, one might define the library to be linked to H drive which is a network drive (there is a trade off of doing this, +: convenient; - : I/O is through network, so extra time for access is expected).
The way to specially library is:
LIBNAME libref 'path';
where libref is
- be 1 to 8 characters in length
- begin with a letter (A-Z, including mixed case characters) or an underscore (_)
continue with any combination of numbers, letters, or underscores.
, and path is the physical path of the storage folder.
Ex: LIBNAME test 'a:\STA108'; /* define "a:\STA108" as the storage folder with reference (libref) "test" */
Note: in SAS, one uses '*' as the symbol to signify the comment line. If your comment contains symbols, you need to use /* comments , or /* comments */.
- The rules for naming SAS datasets.
- be 1 to 32 characters in length
- begin with a letter (A-Z, including mixed case characters) or an underscore (_)
- continue with any combination of numbers, letters, or underscores.
- When one tries to retrieve a SAS data set that was saved in certain folder from previous session, the first and only thing that one needs to do is defining a libref and let it link to that folder. Note that this libref doesn't have to be the same as the one used upon its creation (i.e. the reference name does not go with the data set, it is only meant to tell SAS where it should look for the data).