Princeton University Library Princeton University Library

Search DSS

Finding Data Analyzing Data Citing data

About Us

DSS lab consultation schedule
Sep 1-Oct 16By Zoom appt. here
Oct 19-Dec 4Virtual Zoom Walk-ins
Dec 7-Jan 31By Zoom appt. here
Feb 1-April 30Virtual Zoom Walk-ins
May 3-Aug 31By appt. here
For quick questions email
*No appts. necessary during walk-in hrs.
Note: the DSS lab is open as long as Firestone is open, no appointments necessary to use the lab computers for your own analysis.

Follow DssData on Twitter
See DSS on Facebook

Home Online Help Statistical Packages SAS SAS Data Files

SAS Data Files

Saving SAS Data Files

SAS data files contain both data and information about the data, such as variable and value labels. SAS data files are stored in a special format that is written to and read by the SAS System. It is generally more efficient for SAS to read a SAS data file than to read a raw data file or a file store in some other non-SAS format.

SAS files are saved with special extensions which are used to indicate their file types. The most common type of SAS file, a SAS data file, is saved on UNIX with the extension ".ssd01."

The LIBNAME statement is used to save SAS data files for later processing. Here is the basic format of the LIBNAME statement:

	LIBNAME libref 'UNIX_directory';

where LIBNAME is a keyword, libref is a library reference, and UNIX_directory is the name of a UNIX directory where the SAS data file is saved or will be saved.

  • The libref is used to associate the UNIX_directory with the file that will be read from or written to that directory.
  • The directory name must be enclosed in quotes. The directory must already exist. UNIX file and directory names are case-sensitive: "mydir" is not the same as "MYDIR" which is not the same as "Mydir."

In the following program a SAS data file named "first.ssd01" will be created in the current working directory.

	LIBNAME saveme '.';
	data saveme.first;
	infile '';
	input var1 var2 var3;

The LIBNAME assigns the "saveme" libref to the current working directory, represented by a period ('.'). The DATA statement associates the libref with the name of the file that is being created, "first." This file will be saved in the current working directory.

Moving SAS Files Between Platforms

Suppose you need to move your SAS data files from from UNIX to your PC. SAS data files can be easily moved from one operating system to another as long as they are written in a transportable format. You can create SAS transport files using the SAS XPORT engine or the CPORT procedure.

The following is a program to read a SAS XPORT file and then write it out as a regular SAS data file in UNIX.

     * (1) Use the first LIBNAME statement to indicate the        *
     *  SAS data file that you will be reading.                   *
     *  Place the name of your SAS data file in quotes.           *
     *  Use the XPORT engine to indicate that the file            * 
     *  is save in transport format.                              *;

     libname in xport 'mydata.xport';

     * (2) Use the second LIBNAME statement to indicate the       *
     *  location where you will create the new SAS data file.     *
     *  Place the name of the directory in quotes.                *
     *  A period ('.') represents the current working directory.  *;

     libname out '.';

     * (3) Use the SET statement to read the old data file,       *
     *  and use the DATA statement to write the new data file.    *
     *  Notice that the "in" and "out" librefs are the same as    *
     *  those assigned in the LIBNAME statements above.           *
     *  The new data file will be saved as "newdata.ssd01."       *;

     data out.newdata;
     set in.olddata;

You must make sure that the file name in the data step corresponds to the INTERNAL file name. Even though SAS data files are binary files, it's possible to look at the beginning of the dataset to find the internal dataset name (in case you don't know what name was used when the data set was created). You can also use the CONTENTS procedure in SAS to list the names of data files.

SAS transport files are stored in binary format. The "binary" mode must be invoked if you use FTP (File Transfer Protocol) to copy the files from one computer to another.

You may also want to try using DBMS/Copy to convert and transfer your files.

A Note for DBMS/COPY Users

Where SAS transport files are used to transfer SAS files from one operating system to another (e.g., MVS, UNIX), you can use DBMS/COPY to convert SAS data files for use in other statistical software programs. See the DBMS/COPY documentation for details.

The newest version of DBMS/COPY on UNIX can process SAS 6.09 data files, SAS 6.12 data files, and SAS "export" files created with the XPORT engine as described above.

DBMS/COPY may have trouble processing SAS data files that have been saved in compressed format Make sure that you do not use the following statement in your SAS program if you plan on converting the file with DMBS/COPY:

        options compress=yes;

This page last updated on: