4. Data Sets
SAS Data Sets
When a one-word name is used in the DATA statement of a SAS data step, a temporary data set is created, which is available only during the current job. In order to save a permanent SAS data set that will be available for use in future programs, a two-level name containing a libref must be used in the DATA statement.
SAS data sets differ from .DAT external files in the way the data is stored. Descriptive information about the SAS data set is saved automatically with the file. A SAS data set can not be viewed with the VMS editor, but you can use the SAS procedure CONTENTS to print a description of the file's contents.
In order to read or create a permanent SAS data file, the LIBNAME statement must be used. It associates a libref with a SAS data library, that is, with a VMS directory. The general form of the LIBNAME statement is:
LIBNAME libref engine-name 'VMS directory' engine/host options;
Both the engine/host options list and the engine name are optional. The version 9 engine is identified by the term V9 or BASE in the libname statement. The term BASE is a generic term, referring to the default engine in the current version of SAS, and therefore it will refer to the V9 engine if you're running SAS version 9. If the engine name is omitted, the system will assign the engine based on the type of SAS data sets in the referenced subdirectory. If there are both version 9 datasets and data from earlier versions, then SAS assigns the V9 engine. The following LIBNAME statement associates the libref, MYLIB, and the version 9 engine with the directory, DISK$FACST:[SMITHAA]
LIBNAME MYLIB V9 'DISK$FACST:[SMITHAA]' ;
The libref, MYLIB, can be used to create or access version 9 SAS data sets. When creating stored formats with PROC FORMAT, it is recommended that the libref, LIBRARY be used. This libref is required when the formats are used in subsequent programs.
The following example will create a permanent SAS data set named WEATHER.SAS7BDAT in the faculty directory, SMITHAA. Note that the libref (MYDIR) must be 8 characters or fewer, but the data set name (WEATHER) can contain up to 32 characters. Spaces are not allowed in either the libref or data set name.
LIBNAME MYDIR V9 'DISK$FACST:[SMITHAA]';
DATA MYDIR.WEATHER;
INFILE 'SOUTHEASTERN.DAT';
INPUT TEMP 1-5 PRECIP 7-10 SUNHRS 12-15;
RUN;
To read this SAS data set in another SAS job, you need to use a two-level name and the SET command. The new LIBNAME statement must reference the same directory, but the libref name does not have to be the same. The following example reads the file, WEATHER.SAS7BDAT and creates a new SAS data set, RAINYWEATHER.SAS7BDAT, which is a subset of the original:
LIBNAME MYDIR V9 'DISK$FACST:[SMITHAA]';
DATA MYDIR.RAINYWEATHER;
SET MYDIR.WEATHER;
IF PRECIP>0;
RUN;
Converting Version 8 Data Sets and Catalogs to Version 9
SAS version 8 data files (*.sas7bdat file extension) can be read and updated by SAS 9.1.3 directly without doing any conversion. If you simply read your version 8 data set using a SAS 9.1.3 program and save it, it will be saved as a version 9 file.
However version 8 catalog files need to be exported to transport mode using Proc Cport, and then imported into version 9.1.3 using Proc Cimport. You will need to have access to both SAS version 8 and SAS version 9.
Using SAS version 8, run a program similar to the following. This program assumes that the version 8 catalog files are in the subdirectory [SMITHAA.V8CAT], and the transport file will be created in the subdirectory [SMITHAA.V9FL].
/* CPORT_V8.SAS */
LIBNAME SOURCE ‘DISK$FACST:[SMITHAA.V8CAT]';
FILENAME TRANFILE ‘DISK$FACST:[SMITHAA.V9FL]CATLG.XPT';
PROC CPORT
LIBRARY = SOURCE FILE=TRANFILE
MEMTYPE=CATALOG;
RUN;
Switch to SAS version 9.1.3 and run a program similar to the following. The new version 9 catalog file will be created in the subdirectory [SMITHAA.V9FL].
/* CIMPORT_V9.SAS */LIBNAME V9LIB ‘DISK$FACST:[SMITHAA.V9FL]';
FILENAME TRANFILE ‘DISK$FACST:[SMITHAA.V9FL]CATLG.XPT';
PROC CIMPORT
LIBRARY = V9LIB INFILE=TRANFILE;
RUN;
