You can use SAS views in the following ways:
as input to other DATA steps or PROC steps
to migrate data to SAS data files or to database management systems that are
supported by SAS
in combination with other data sources using PROC SQL
as pre-assembled sets of data for users of SAS/ASSIST software, enabling them to
perform data management, analysis, and reporting tasks regardless of how the data is
stored
When to Use SAS Views
Consider the following in order to determine whether a SAS data file or a SAS view is
better for your purposes:
Data files use additional disk space; SAS views use additional processing time.
Data file variables can be sorted and indexed before using; SAS views must process
data in its existing form during execution.
DATA Step Views
Definition of a DATA Step View
A DATA step view is a native view that has the broadest scope of any SAS view. It
contains a stored DATA step program that can read data from a variety of sources,
including:
raw data files
SAS data files
PROC SQL views
SAS/ACCESS views
DB2, ORACLE, or other DBMS data
Creating DATA Step Views
In order to create a DATA step view, specify the VIEW= option after the final data set
name in the DATA statement. The VIEW= option tells SAS to compile, but not to
execute, the source program and to store the compiled code in the input DATA step view
that is named in the option.
For example, the following statements create a DATA step view named Dept.A:
libname dept 'SAS-library';
data dept.a / view=dept.a;
… more SAS statements …
run;
DATA Step Views 677
If the SAS view exists in a SAS library and if you use the same member name to create a
new view definition, then the old SAS view is overwritten.
Beginning with SAS 8, DATA step views retain source statements. You can retrieve
these statements using the DESCRIBE statement. The following example uses the
DESCRIBE statement in a DATA step view in order to write a copy of the source code
to the SAS log:
data view=inventory;
describe;
run;
For more information about how to create SAS views and use the DESCRIBE statement,
see the DATA statement in SAS DATA Step Statements: Reference.
What Can You Do with a DATA Step View?
Using a DATA step view, you can do the following:
directly process any file that can be read with an INPUT statement
read other SAS data sets
generate data without using any external data sources and without creating an
intermediate SAS data file
Because DATA step views are generated by the DATA step, they can manipulate and
manage input data from a variety of sources including data from external files and data
from existing SAS data sets. The scope of what you can do with a DATA step view,
therefore, is much broader than that of other types of SAS views.
Differences between DATA Step Views and Stored Compiled DATA
Step Programs
DATA step views and stored compiled DATA step programs differ in the following
ways:
a DATA step view is implicitly executed when it is referenced as an input data set by
another DATA or PROC step. Its main purpose is to provide data, one record at a
time, to the invoking procedure or DATA step.
a stored compiled DATA step program is explicitly executed when it is specified by
the PGM= option in a DATA statement. Its purpose is usually a more specific task,
such as creating SAS data files, or originating a report.
For more information about stored compiled DATA step programs, see Chapter 30,
“Stored Compiled DATA Step Programs,” on page 685.
Restrictions and Requirements
Global statements do not apply to a DATA step view. Global statements such as the
FILENAME, FOOTNOTE, LIBNAME, OPTIONS, and TITLE statements, even if
included in the DATA step that created the SAS view, have no effect on the SAS view. If
you do include global statements in your source program statements, SAS stores the
DATA step view but not the global statements. When the view is referenced, actual
execution can differ from the intended execution.
When a view is created, the labels for the variable that it returns are also created. If a
DATA step view reads a data set that contains variable labels and a label is changed after
678 Chapter 29 SAS Views

Get SAS 9.4 Language Reference, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.