O'Reilly logo

SAS 9.4 Language Reference, 6th Edition by SAS Institute

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 671
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 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 28,
“Stored Compiled DATA Step Programs,” on page 679.
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
672 Chapter 27 SAS Views

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required