Chapter Contents |
Previous |
Next |
Definition |
Creating DATA Step Views |
DATA view-name <data-set-name-1
<(data-set-options-1)>>
<. . .data-set-name-n <(data-set-options-n)>> / VIEW=view-name <(<password-option><SOURCE=source-option>)>; |
where
If the SAS data view already exists in a SAS data library and you use the same member name to create a new view definition using the same member name, then the old data view is overwritten.
For more information on how to create data views, see the DATA statement in SAS Language Reference: Dictionary.
Recent Enhancements to Views |
Examples |
libname dept 'SAS--data--library'; data dept.a / view=dept.a; ... more SAS statements ... run;
data budget_jan / view=budget_jan; ... more SAS statements ... run;
data viewname view=inventory; describe; run;
For information about the DESCRIBE statement, see the SAS Language Reference: Dictionary.
What Can You Do with a Data Step View? |
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 data views.
Differences between DATA Step Views and Stored Compiled DATA Step Programs |
Restrictions and Requirements |
Performance Considerations |
Example 1: Merging Data to Produce Reports |
For example, the following statements define DATA step view "MYV8LIB", which merges the sales figures in the data file V8LR.CLOTHES with the sales figures in the data file V8LR.EQUIP. The data files are merged by date, and the value of the variable TOTAL is computed for each date.
libname myv8lib 'SAS-data-library'; data myv8lib.qtr1 / view=myv8lib.qtr1; merge v8lrclother.clothes myv8lr.equip; by date; total = cl_v8lr + eq_v8lr; run;The following PROC print statement executes the view:
proc print data = myv8lib.qtr1; run;
Example 2: Producing Additional Output Files |
In this example, the DATA step reads an external file named STUDENT, which contains student data, then writes observations that contain known problems to MYV8LIB.PROBLEMS. The DATA step also defines the DATA step view MYV8LIB.CLASS. The DATA step does not create a SAS data file named MYV8LIB.CLASS.
The FILENAME and the LIBNAME statements are both global statements and must exist outside of the code that defines the view, because views cannot contain global statements.
Here are the contents of the external file STUDENT: dutterono MAT 3 lyndenall MAT frisbee MAT 94 SCI 95 zymeco ART 96 dimette 94 mesipho SCI 55 merlbeest ART 97 scafernia 91 gilhoolie ART 303 misqualle ART 44 xylotone SCI 96 Here is the DATA step that produces the output files:
libname myv8lib 'SAS-data-library'; filename student 'external-file-specification'; [1] data myv8lib.class(keep=name major credits) myv8lib.problems(keep=code date) / view=myv8lib.class; [2] infile student; input name $ 1-10 major $ 12-14 credits 16-18; [3] select; when (name=' ' or major=' ' or credits=.) do code=01; date=datetime(); output myv8lib.problems; end; [4] when (0<credits<90) do code=02; date=datetime(); output myv8lib.problems; end; [5] otherwise output myv8lib.class; end; run; [6]
The following example shows how to print the files created previously. The data view MYV8LIB.CLASS contains the observations from STUDENT that were processed without errors. The data file MYV8LIB.PROBLEMS contains the observations that contain errors.
If the data frequently changes in the source data file STUDENT, there would be different effects on the returned values in the the SAS data view and the SAS data file:
A SAS data view dynamically updates from its source files each time it is used. A SAS data file, each time it is used, remains the same, unless new data is written directly to the file.
filename student 'external-file-specification'; libname myv8lib 'SAS-data-library'; [7] proc print data=myv8lib.class; run; [8] proc print data=myv8lib.problems; format date datetime18.; run; [9]
Reference a library called MYV8LIB. Tell SAS where a file that associated with the fileref STUDENT is stored. | |
Create a data file called PROBLEMS and a data view called CLASS and specify the column names for both data sets. | |
Select the file that is referenced by the fileref STUDENT and select the data in character format that resides in the specified positions in the file. Assign column names. | |
When data in the columns NAME, MAJOR or CREDITS is blank or missing, assign a code of "01" to the observation where the missing value occurred. Also assign a SAS datetime code to the error and place the information in a file called "PROBLEMS". | |
When the amount of credits is greater than zero, but less than ninety, list the observations as code 02 in the file called PROBLEMS and assign a SAS datetime code to the observation. | |
Place all other observations, which have none of the specified errors, in the SAS data view called MYV8LIB.CLASS. | |
The FILENAME statement assigns the fileref STUDENT to an external file. The LIBNAME statement assigns the libref MYV8LIB to a SAS data library. | |
The first PROC PRINT step calls the data view MYV8LIB.CLASS. The data view extracts data on the fly from the file referenced as STUDENT. | |
This PROC PRINT step prints the contents of the data file MYV8LIB.PROBLEMS. |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.