2 File Reference and Option Setting
2 File Reference and Option Setting
1. Defining Libraries
where
libref is 1 to 8 characters long, begins with a letter or underscore, and
contains only letters, numbers, or underscores.
'SAS-data-library is the name of a SAS data library in which SAS
data files are stored. The specification of the physical name of the library
differs by operating environment.
The LIBNAME statement is global. The effect remains until you modify them, cancel
them, or end your SAS session.
The LIBNAME statement assigns the libref for the current SAS session only. The
contents of the library, however, still exist on your operating system.
Files that were created with other software products can also be referenced by using
the appropriate engine for that file type.
where
engine is the name of a library engine that is supported in your operating
environment. Examples are BMDP, OSIRIS, and SPSS files.
Example 1
Suppose that the operating system is Windows. What does the following program do?
Create a library reference with which SPSS files can be directly accessed.
Example 2
Suppose that the operating system is UNIX. What does the following program do?
1
Create a library reference with which SAS files can be directly accessed.
Example 3
Suppose that the operating system is Windows. What is wrong of the following program?
where
SAS-file-specification specifies an entire library or a specific
SAS data set within a library. SAS-file-specification takes one of
the following forms:
o <libref.>SAS-data-set names one SAS data set to process.
o <libref.>_ALL_ requests a listing of all files in the library.
NODS is an option that suppresses the printing of detailed information about
each file when you specify _ALL_ . (You can specify NODS only when you
specify _ALL_ .)
DATASETS procedure shows the contents of a SAS library or a SAS data set, and
performs management (e.g. copying, deleting, and modifying) of data sets.
PROC DATASETS;
CONTENTS DATA=SAS-file-specification <options>;
QUIT;
2
Generally, PROC CONTENTS and PROC DATASETS are the same in terms of
functionality. The options for the PROC CONTENTS statement and the CONTENTS
statement in the DATASETS procedure are the same.
PROC CONTENTS and PROC DATASETS list variables alphabetically by default.
To list variable names in the order of their logical position (or creation order) in the
data set, specify the VARNUM option in PROC CONTENTS or in the CONTENTS
statement in PROC DATASETS.
PROC PRINT displays the contents of a data set:
PROC FREQ displays the table which contains the frequencies of value of each
variables of a data set:
Example 4
Write a SAS program that prints the descriptor portion of files in the library Sasuser with
all variables shown in alphabetically order.
Example 5
What will be shown in the Output windows after each of the following program is executed?
(a) proc contents data=summer._all_ nods;
run;
3
(c) proc datasets;
contents data=sasuser._all_ varnum;
run;
There are two formats for output: LISTING and HTML. To specify LISTING as the
output, use ODS LISTING statement; to specify HTML as the format, use ODS
HTML statement. To turn off HTML or LISTING format, use ODS HTML CLOSE or
ODS LISTING CLOSE respectively.
OPTIONS statement changes the settings from that point onward:
OPTIONS options;
4
FIRSTOBS= and OBS= can be data set options. The data set options override the
system options in the procedure only. For example,
Example 6
What will be shown in the Output windows after the following SAS program is executed?
options nodate firstobs=5;
proc print data=summer.airports;
run;
The first PROC PRINT shows the whole dataset starting from
observation 5. The date is suppressed.
Example 7
Suppose that YEARCUTOFF=1920. How are the following dates interpreted? What if
YEARCUTOFF=1950?
1941
2015
1930
1995
5
Example 8
Example 9
proc datasets;
contents data=summer.heart;
run;
4. Answers of Examples
5.
6
(a) The contents of the library ‘summer’. The detail
information of each file is suppressed.
6. The first PROC PRINT shows the whole dataset starting from
observation 5. The date is suppressed. The second PROC PRINT
shows observation 5 only. The page number and the date are
both suppressed.