Statistical Consulting Center - UMass AMherst
 

Home
Site Licenses
Computer Labs
OITUNIX
Direct Purchase

Statistical Software
Instructional Materials

What's New
Current Releases
Patches


Resources

BCCUMA

Datasets

Workshops

Online Docs
SAS 8.2
SAS 9.1.3
SIR 2002

 

Statistical Software > SAS/WIN Web > Creating Permanent SAS Datasets

SAS Online Tutorial

IX. Creating Permanent SAS datasets

Up to this point all the SAS datasets, we have been working with, have been temporary (i.e. stored in the WORK directory). Now we will learn three ways to make a permanent SAS dataset : Use of the Viewtable window with Save as , the LIBNAME statement with a data step, and Using the full path name with the data step. We will work with the temporary SAS dataset (minifix), created in Section VIII.


Using Save as in Viewtable to create permanent SAS dataset

From the SAS Explorer window, double click on Libraries, then double click on Work library and finally double click on the Minifix dataset (note: If you do not see this dataset in the Work library then you need to return to Section VIII and Manipulating SAS data and create it.). This opens the minifix dataset in the Viewtable window. Choose the Save As option from the File menu.

In order to save a permanent SAS data set, you need to create a new library. Click on the New Library icon (it looks like a file drawer) in the Save as dialog box as shown below:



When the New Library dialog box appears, type a name for the new library and select its location (path). For this example, we will use library name ref and path a:\ This will save the permanent dataset on diskette.



Click OK. In the Save As dialog box, select ref under libraries on the left panel, and enter a name in the Member Name field. We will use the member name minifix. Click Save.

You have now saved data into a permanent SAS dataset called minifix in directory a:\. Using Windows Explorer, if you look at in a:\, you will see a file call minifix.sas7bdat. All SAS datasets get the extension sas7bdat.


The LIBNAME statement and Data step to create a permanent SAS dataset

Another method for creating a permanent SAS dataset, using programming statements is to use the LIBNAME statement to create a new library (ref) and a Data step with a two part name (ref.minifix). Type or copy/paste the program lines below into the Editor Window:


libname ref 'a:\';
data ref.minifix; set minifix;
run;


After you submit these statements, you will get the following log window:



From the above Log window, the first NOTE: shows that the library name ref has been created, and refers to the location 'a:\'. The next NOTE indicates that 91 observations were read from the temporary dataset WORK.MINIFX. The third NOTE: shows that the dataset ref.minix has been saved with 91 observations and 9 variables. This dataset is permanent because the first part of the name is not work. Since the library ref refers to a:\, the permanent SAS dataset is saved in a:\.

Using Windows Exlporer, if you look in a:\, you should see a file called minifix.sas7bdat. Even though the Windows filename is minifix.sas7bdat, note that within the SAS program you refer to a SAS dataset with a library name and the first part of the file name, e.g. ref.minifix.. Since all SAS datasets have the extension .sas7bdat, there is no need to mention it.

Using a LIBNAME statement and two part SAS dataset name is recommended because it is most native to SAS. It is the same in all versions of SAS, on all operating systems, and therefore makes your programs most easily transportable. It also makes it easy to refer to many datasets in the same location, or to the same dataset many times, without having to type long paths.


Using the full path name with the Data Step to create a permanent SAS dataset

Instead of establishing a library name with a LIBNAME statement, we can create a permanent SAS dataset using the full pathname of the library (i.e. directory). When you use the full path name, you must enclose it in quotes since it includes special characters (i.e. colon and slash). Type or copy/paste the program lines below in the Editor Window:


data 'a:\minifix'; set minifix;
run;


After you submit these statements, you will get the following log window:



From the Log window above, the second NOTE: indicates a:\minifix has been created. There should now be a dataset called minifix.sas7bdat in the a:\ directory. Check this by using Windows explorer to look at the a: drive.

Even though the Windows filename is minifix.sas7bdat, note that within the SAS program you refer to a SAS dataset by providing the path and the first part of the file name, e.g. ' a:\minifix'. Since all SAS datasets have the extension .sas7bdat, there is no need to mention it.


Using permanent SAS datasets

If you have a permanent SAS dataset then you can begin a SAS session and access it directly from a procedure without using a data step. You can access the permanent SAS dataset either by creating a library name that points to the directory where it is stored and using a two part name, or by using the full pathname.

Using a LIBNAME statement and two part SAS dataset name is recommended because it is most native to SAS. It is the same in all versions of SAS, on all operating systems, and therefore makes your programs most easily transportable. It also makes it easy to refer to many datasets in the same location, or to the same dataset many times, without having to type long paths.


Accessing a permanent SAS dataset using Libname statement and two part name

First, make sure that minifix.sas7bdat exists on a:\. If not, go back to the previous sections and make it so. Exit SAS (from the File menu select exit). Now start a new SAS session and type or copy/paste the following program lines into the Editor Window:


libname new 'a:\';
proc freq data=new.minifix;
Tables ran smoke sex;
run;


After you submit you will see the following Log and Output windows:


Note that the library name assigned in this program, new, is not the same as was used in the program that saved the permnanent dataset. The library name assignment only exists for the duration of a sas session. What matters is that the library name assigned in the program that saved the data (ref) and the one that uses that data (new) both refer to the location a:\.


Accessing a permanent SAS dataset using the full pathname

Type or copy/paste the following programming statements into the Editor Window:


proc freq data='a:\minifix';
tables ran smoke sex;
run;


After you submit the above statements the Log window is as follows and the Output window is the same as the previous one:



Home
| Back


2004 University of Massachusetts Amherst. Site Policies.