SAS Views provide all the functionality and flexibility of SAS data sets, but occupy only a minuscule fraction of the space of a full SAS data set. This is accomplished by SAS compiling and storing the DATA step code that reads data from raw files or other SAS data sets, then executing that code whenever the View is referenced. The View acts as sort of a "map" to the source data, instead of making a complete copy of it in SAS data format. Execution of a View is a bit slower when compared with the use of a "real" SAS data set, but the difference is noticeable only on very large sets of data.
SAS Views can read SAS data sets on disk, and raw data stored on disk as well as on UniTree. (Using raw data stored on UniTree is discussed elsewhere in this document.) Basically, anything a DATA step can do a View can also do, using far less space to store the "results".
In one test, a regular SAS data set was created from a 2.5Mb raw data file on UNIX disk. Not all fields were read, resulting in a SAS data set of just under 800K. A SAS View also was created to read the same variables and provide the same information to SAS PROCs and other DATA steps. The View occupied 6144 bytes! In situations where raw data must reside on disk, including those situations where the raw data are continually updated, SAS Views can save space and allow access to the most recent version of raw data, without the need to create and store actual SAS data sets.
SAS Views are documented in the SAS OnlineDoc(tm), listed in References at the end of this document.
To create a SAS View, add the VIEW= option to the DATA statement. The SAS data view name provided after VIEW= must be the same as at least one of the SAS data set names mentioned in the DATA step statements, but may not be the same as a SAS View or SAS data set already in the same library. Virtually all the language of the DATA step is the same as it would be if a true SAS data set were being created, except that the VIEW= option is added. For example, the following statements read raw data and create a SAS View called view1.ssv01:
libname viewout '~/sasviews';
filename raw1 '~/rawdata/file1.raw';
data viewout.test1 / view=viewout.test1;
infile raw1; input var1 var2 var3; run;
libname viewout '~/sasviews';
filename raw1 '~/rawdata/file1.raw';
proc print data=viewout.test1;
libname allsas '~/sasdata';
libname viewstor '~/sasviews';
data viewstor.females / view=viewstor.females;
set allsas.master; if sex='f';
data viewstor.males / view=viewstor.males;
set allsas.master; if sex='m';
To process the two subsets in the example just above, the following might be used:
libname allsas '~/sasdata';
libname viewstor '~/sasviews';
proc means data=viewstor.females;
var <--variable list-->
proc reg data=viewstor.males;
model <--model specifications-->
run;
LIBNAME ALLSAS statement is needed to point to
the master SAS data set,
and the LIBNAME VIEWSTOR is needed to
point to the View. Of course, they could both be stored in the
same subdirectory if desired.Using SAS Views requires attention to some important details and warnings: