Begins a DATA step and provides names for any output such as SAS data sets, views, or programs.
| Valid in: | DATA step |
|---|---|
| Categories: | CAS |
| File-Handling | |
| Type: | Declarative |
Table of Contents
If you do not specify a name for the output data set or specify the reserved name NULL in a DATA statement, SAS automatically assigns the names DATA1, DATA2, and so on, to each successive data set that you create. This feature is referred to as the DATAn naming convention. The maximum n value that is currently allowed is 9999.
names the SAS data file or DATA step view that the DATA step creates. To create a DATA step view, you must specify at least one data-set-name and that data-set-name must match view-name.
| Restriction | data-set-name must conform to the rules for SAS names, and additional restrictions might be imposed by your operating environment. |
|---|---|
| Tips | Instead of using a data set name, you can specify the physical pathname to the file using syntax that your operating system understands. The pathname must be enclosed in single or double quotation marks. |
| If _NULL_ is specified as the data set name, SAS does not create a data set when it executes the DATA step. For an example, see Creating a Custom Report. | |
| See | Names in the SAS Language in SAS Language Reference: Concepts |
specifies optional arguments that the DATA step applies when it writes observations to the output data set.
| See | SAS Data Set Options: Reference for a definition and list of data set options. |
|---|---|
| Example | Creating Multiple Data Files and Using Data Set Options |
suppresses the output of all variables to the SAS log when the value of _ERROR_ is 1.
| Restriction | NOLIST must be the last option in the DATA statement. |
|---|
assigns a password to a stored compiled DATA step program or a DATA step view.
These password options are available:
assigns an ALTER password to a SAS data file. The password enables you to protect or replace a stored compiled DATA step program or a DATA step view.
| Alias | PROTECT= |
|---|---|
| Requirements | 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. |
| 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. |
assigns a READ= password and an ALTER= password. Both passwords are set to the same value.
assigns a READ password to a SAS data file. The password enables you to read or execute a stored compiled DATA step program or a DATA step view.
| Alias | EXECUTE= |
|---|---|
| Requirements | 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. |
| 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 executes 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. |
names the stored compiled program that SAS creates or executes in the DATA step. To create a stored compiled program, specify a slash (/) before the PGM= option. To execute a stored compiled program, specify the PGM= option without a slash (/).
| Restriction | This argument is not supported in a DATA step that runs in CAS. |
|---|---|
| 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. |
| Example | Storing and Executing a Compiled Program |
specifies one of these source options:
encrypts and saves the source code, including all character string constants, that created a stored compiled DATA step program or a DATA step view.
| Notes | Beginning in 9.4M9, ENCRYPTALL replaces option ENCRYPT. ENCRYPTALL uses SAS004 encryption. ENCRYPT uses SAS proprietary encoding SAS002. For more information about SAS encryption levels, see Concepts: PWENCODE Procedure in Base SAS Procedures Guide. Consider re-creating stored programs and views that were created using ENCRYPT to take advantage of the stronger encryption. |
|---|---|
| Stored programs and views created with ENCRYPTALL cannot be used with releases prior to 9.4M9. | |
| Tip | If you encrypt source code, use the ALTER password option as well. SAS issues a warning message if you do not use ALTER. |
does not save the source code.
CAUTION
If you use the NOSAVE option for a DATA step view, the view cannot be migrated or copied from one version of SAS to another version.
saves the source code that created a stored compiled DATA step program or a DATA step view.
| Default | SAVE |
|---|---|
| Restriction | This argument is not supported in a DATA step that runs in CAS. |
names a view that the DATA step uses to store the input DATA step view.
| Restrictions | This argument is not supported in a DATA step that runs in CAS. |
|---|---|
| view-name must match one of the output data set names. | |
| SAS creates only one view in a DATA step. | |
| Tips | 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 when the view is executed. |
| SAS macro variables resolve when the view is created. Use the SYMGET function to delay macro variable resolution until the view is processed. | |
| Examples | Creating Input DATA Step Views |
| Creating a View and a Data File |
enables you to debug your program interactively by helping identify logic errors, and sometimes data errors.
| Restriction | This argument is not supported in a DATA step that runs in CAS. |
|---|---|
| See | SAS Code Debugger: User’s Guide |
| Example | data test / debug; x=round(height); run; |
enables the LIST statement to write log data in hexadecimal format for all lines of input data. This argument is available beginning with SAS 9.4M6.
| See | For more information about using the HEXLISTALL option with the LIST statement, see Listing Hexadecimal Values for Input Data. |
|---|
specifies that a note is printed to the SAS log for the beginning and end of each DO-END and SELECT-END nesting level. The NESTING option enables you to debug mismatched DO-END and SELECT-END statements and is particularly useful in large programs where the nesting level is not obvious.
specifies the maximum number of nested LINK statements.
associates a DATA step with a CAS session. The value for the SESSREF= option represents the current active session.
| Interactions | If the DSCAS system option is set to NODSCAS, either the SESSREF= or SESSUUID= option is required to run the DATA step in CAS. |
|---|---|
| If the DATA step running in CAS has no input tables, it runs in a single thread unless the SESSREF or SESSUUID option is specified. |
specifies the CAS session where the DATA step runs. The session-uuid is the universally unique identifier (UUID) that is associated with a CAS session. One way to create a session and retrieve the UUID for the session is with the CAS statement or LIBNAME statement.
| Interactions | If the DSCAS system option is set to NODSCAS, either the SESSREF= or SESSUUID= option is required to run the DATA step in CAS. |
|---|---|
| If the DATA step running in CAS has no input tables, it runs in a single thread unless the SESSREF or SESSUUID option is specified. | |
| Tip | One way to create a session and retrieve the UUID for the session is with the CAS statement or LIBNAME statement. |
specifies whether to run the DATA step in a single thread in CAS. By default, a DATA step running in CAS runs in a single thread when there is no CAS input table specified. The DATA step running in CAS runs in multiple threads by default when there is an input CAS table specified. For example, the following DATA step runs by default in a single thread in CAS:
libname mycas cas;
data mycas.test;
x='No input table specified';
run;
The following note is
returned in the log: NOTE: The DATA step has no input
data set and will run in a single thread.
This DATA step runs in multiple threads in CAS by default:
libname mycas cas;
data mycas.class;
set mycas.class;
run;
To redistribute a CAS table, you can use the Partition action in the Tables action set. For information about redistributing a table, see partition in SAS Viya: System Programming Guide.
If the DATA step fails to run in CAS because the requirements for running in the server are not met, then the DATA step runs in SAS automatically. When the DATA step runs in SAS, it always runs in a single thread.
runs the DATA step program in a single thread only when there are no CAS input tables. This option is useful when writing a DATA step that generates only output data to a table. NOINPUT is the default for DATA step processing in CAS when there is no input table specified.
runs the DATA step program in all threads. If there are 4 workers and each worker supports 32 threads, the DATA step program runs in 128 threads. NO is the default for DATA step processing in CAS as long as there is an input table specified. Otherwise, without an input table, the DATA step in CAS runs in a single thread.
runs the DATA step program in a single thread. As rows from input tables are processed, a copy of every row is transferred to a single node and processed in the single thread. This action incurs a performance penalty for the data transfer, data duplication, and limited processing that is possible with a single thread. A DATA step that is running in SAS always runs in a single thread.
| Default | NOINPUT |
|---|---|
| See | SAS Cloud Analytic Services: DATA Step Programming |
specifies the number of threads to use to run the DATA step in CAS.
| Requirement | This number must be greater than or equal to 0. A value of 0 indicates to run the DATA step program using the maximum number of threads allowed. |
|---|
The DATA step begins with the DATA statement. You use the DATA statement to create these types of output: SAS data sets, data views, and stored programs. You can specify more than one output in a DATA statement. However, only one of the outputs can be a data view. You create a view by specifying the VIEW= option and create a stored program by specifying the PGM= option.
If you use both a READ password and an ALTER password in creating a stored compiled DATA step program or a DATA step view, these items apply:
| The DESCRIBE statement does not execute. |
| In batch mode, the EXECUTE statement has no effect. |
| In interactive mode, SAS prompts you for a READ password. If the READ password is valid, SAS processes the EXECUTE statement. If it is invalid, SAS does not process the EXECUTE statement. |
| If you enter a valid ALTER password, SAS executes both the DESCRIBE and EXECUTE statements. |
| If you enter an invalid ALTER password, SAS processes the EXECUTE statement but not the DESCRIBE statement. |
Use the DATA statement to create one or more output data sets. You can use data set options to customize the output data set.
Here is a DATA step that creates two output data sets, EXAMPLE1 and EXAMPLE2. This DATA step example 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;
You can create DATA step views and execute them at a later time. This 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, see DATA Step Views in SAS Language Reference: Concepts.
The ability to compile and store DATA step programs enables you to execute the stored programs later. Stored compiled DATA step programs can reduce processing costs by eliminating the need to compile DATA step programs repeatedly. This DATA step example compiles and stores a DATA step program. It uses the ALTER password option, which enables 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, see Stored Compiled DATA Step Programs in SAS Language Reference: Concepts.
This 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 more information, see DESCRIBE Statement.
This 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 library';
data pgm=stored.employee_list;
describe;
execute;
run;
libname stored 'SAS library';
data pgm=stored.test_program;
describe;
execute;
. . .more SAS statements. . .
run;
For more information, see DESCRIBE Statement and EXECUTE Statement.
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-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-library-1';
libname theirlib 'SAS-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-library-1 ';
libname stored 'SAS-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.
data sample;
input Name $ TotalItems $;
datalines;
Lin 328
Susan 433
Ken 156
Pat 340
;
proc print data=sample;
run;
libname stored 'SAS-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 prompts you for it.
data pgm=stored.items (alter=klondike);
describe;
execute;
run;
This program has two nesting levels. SAS generates four log messages, one begin and end message for each nesting level.
data _null_ /nesting;
do i = 1 to 10;
do j = 1 to 5;
put i= j=;
end;
end;
run;
6 data _null_ /nesting;
7 do i = 1 to 10;
-
719
NOTE 719-185: *** DO begin level 1 ***.
8 do j = 1 to 5;
-
719
NOTE 719-185: *** DO begin level 2 ***.
9 put i= j=;
10 end;
---
720
NOTE 720-185: *** DO end level 2 ***.
11 end;
---
720
NOTE 720-185: *** DO end level 1 ***.
12 run;