Chapter Contents |
Previous |
Next |
DATA |
Valid: | in a DATA step |
Category: | File-handling |
Type: | Declarative |
Syntax |
DATA <data-set-name-1
<(data-set-options-1)>>
<. . .data-set-name-n <(data-set-options-n)>>; |
DATA _NULL_; |
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>)>; |
DATA data-set-name / PGM=program-name <(<password-option><SOURCE=source-option>)>; |
DATA
VIEW=view-name <(password-option)>;
|
DATA
PGM=program-name
<(password-option)>;
|
Arguments |
Restriction: | data-set-name must conform to the rules for SAS names, and additional restrictions may be imposed by your operating environment. |
Tip: | You can execute a DATA step without creating a SAS data set. See Creating a Custom Report for an example. For more information, see When Not Creating a Data Set. |
See also: | For details on the types of SAS data set names and when to use each type, see SAS Language Reference: Concepts. |
See also: | Data Set Options for more information. |
Featured in: | Creating Multiple Data Files and Using Data Set Options |
Restriction: | view-name must match one of the data set names. |
Restriction: | SAS creates only one view in a DATA step. |
Tip: | If you specify additional data sets in the DATA statement, SAS creates these data sets when the view is processed in a subsequent DATA or PROC step. Views have the capability of generating other data sets at the time the view is executed. |
Tip: | SAS macro variables resolve when the view is created. Use the SYMGET function to delay macro variable resolution until the view is processed. |
Featured in: | Creating Input DATA Step Views and Creating a View and a Data File |
Requirement: | If you use an ALTER password in creating a stored compiled DATA step program or a DATA step view, an ALTER password is required to replace the program or view. |
Requirement: | If you use an ALTER password in creating a stored compiled DATA step program or a DATA step view, an ALTER password is required to execute a DESCRIBE statement. |
Alias: | PROTECT= |
Requirement: | If you use a READ password in creating a stored compiled DATA step program or a DATA step view, a READ password is required to execute the program or view. |
Requirement: | If you use a READ password in creating a stored compiled DATA step program or a DATA step view, a READ password is required to execute DESCRIBE and EXECUTE statements. If you use an invalid password, SAS will execute the DESCRIBE statement. |
Tip: | If you use a READ password in creating a stored compiled DATA step program or a DATA step view, no password is required to replace the program or view. |
Alias: | EXECUTE= |
Tip: | If you encrypt source code, use the ALTER password option as well. SAS issues a warning message if you do not use ALTER. |
Default: | SAVE |
Tip: | SAS macro variables resolve when the stored program is created. Use the SYMGET function to delay macro variable resolution until the view is processed. |
Featured in: | Storing and Executing a Compiled Program |
Details |
If you use both a READ and an ALTER password in creating a stored compiled DATA step program or a DATA step view, the following items apply:
Use the DATA statement to create one or more output data sets. You can use data set options to customize the output data set. The following DATA step creates two output data sets, example1 and example2. It uses the data set option DROP to prevent the variable IDnumber from being written to the example2 data set.
data example1 example2 (drop=IDnumber); set sample; . . .more SAS statements. . . run;
Usually, the DATA statement specifies at least one data set name that SAS uses to create an output data set. However, when the purpose of a DATA step is to write a report or to write data to an external file, you may not want to create an output data set. Using the keyword _NULL_ as the data set name causes SAS to execute the DATA step without writing observations to a data set. This example writes to the SAS log the value of Name for each observation. SAS does not create an output data set.
data _NULL_; set sample; put Name ID; run;
You can create DATA step views and execute them at a later time. The following DATA step example creates a DATA step view. It uses the SOURCE=ENCRYPT option to both save and encrypt the source code.
data phone_list / view=phone_list (source=encrypt); set customer_list; . . .more SAS statements. . . run;
For more information about DATA step views, see
SAS Language Reference: Concepts.
The ability to compile and store DATA step programs allows you to execute the stored programs later. This can reduce processing costs by eliminating the need to compile DATA step programs repeatedly. The following DATA step example compiles and stores a DATA step program. It uses the ALTER password option, which allows the user to replace an existing stored program, and to protect the stored compiled program from being replaced.
data testfile / pgm=stored.test_program (alter=sales); set sales_data; . . .more SAS statements. . . run;
For more information about stored compiled DATA step programs, see
SAS Language Reference: Concepts.
The following example uses the DESCRIBE statement in a DATA step view to write a copy of the source code to the SAS log.
data view=inventory; describe; run;
For information about the DESCRIBE statement, see
DESCRIBE.
The following example executes a stored compiled DATA step program. It uses the DESCRIBE statement to write a copy of the source code to the SAS log.
libname stored 'SAS data library'; data pgm=stored.employee_list; describe; execute; run;
SAS data library'more SAS statements
For information about the DESCRIBE statement, see DESCRIBE. For information about the EXECUTE statement, see EXECUTE.
Examples |
This DATA statement creates more than one data set, and it changes the contents of the output data sets:
data error (keep=subject date weight) fitness(label='Exercise Study' rename=(weight=pounds));The ERROR data set contains three variables. SAS assigns a label to the FITNESS data set and renames the variable weight to pounds.
This DATA step creates an input DATA step view instead of a SAS data file:
libname ourlib 'SAS-data-library'; data ourlib.test / view=ourlib.test; set ourlib.fittest; tot=sum(of score1-score10); run;
This DATA step creates an input DATA step view named THEIRLIB.TEST and an additional temporary SAS data set named SCORETOT:
libname ourlib 'SAS-data-library-1'; libname theirlib 'SAS-data-library-2'; data theirlib.test scoretot / view=theirlib.test; set ourlib.fittest; tot=sum(of score1-score10); run;SAS does not create the data file SCORETOT until a subsequent DATA or PROC step processes the view THEIRLIB.TEST.
The first DATA step produces a stored compiled program named STORED.SALESFIG:
libname in 'SAS-data-library-1 '; libname stored 'SAS-data-library-2 '; data salesdata / pgm=stored.salesfig; set in.sales; qtr1tot=jan+feb+mar; run;SAS creates the data set SALESDATA when it executes the stored compiled program STORED.SALESFIG.
data pgm=stored.salesfig; run;
The second DATA step in this program produces a custom report and uses the _NULL_ keyword to execute the DATA step without creating a SAS data set:
data sales; input dept : $10. jan feb mar; datalines; shoes 4344 3555 2666 housewares 3777 4888 7999 appliances 53111 7122 41333 ; data _null_; set sales; qtr1tot=jan+feb+mar; put 'Total Quarterly Sales: ' qtr1tot dollar12.; run;
The first DATA step creates a stored compiled DATA step program called STORED.ITEMS. This program includes the ALTER password, which limits access to the program.
libname stored 'SAS-data-library';
data employees / pgm=stored.items (alter=klondike); set sample; if TotalItems > 200 then output; run;
This DATA step executes the stored compiled DATA step program STORED.ITEMS. It uses the DESCRIBE statement to print the source code to the SAS log. Because the program was created with the ALTER password, you must use the password if you use the DESCRIBE statement. If you do not enter the password, SAS will prompt you for it.
data pgm=stored.items (alter=klondike); describe; execute; run;
See Also |
Statements:
| |||||
Data Set Options |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.