Chapter Contents

Previous

Next
DATA

DATA


Begins a DATA step and provides names for any output SAS data sets

Valid: in a DATA step
Category: File-handling
Type: Declarative


Syntax
Without Arguments
Arguments
Details
Suppressing the Output Data Set
Using Stored Compiled Programs
Examples
Example 1: Creating Multiple Data Files and Using Data Set Options
Example 2: Creating Input DATA Step Views
Example 3: Creating a View and a Data File
Example 4: Storing and Executing a Compiled Program
Example 5: Creating a Custom Report
See Also

Syntax

DATA <data-set-name-1 <(data-set-options-1)>>
<. . .data-set-name-n <(data-set-options-n)>>
</ VIEW=view-name | PGM=program-name>;
DATA PGM=program-name;

Without Arguments

If you omit the arguments, the DATA step automatically names each successive data set that you create as DATAn, where n is the smallest integer that makes the name unique.


Arguments

data-set-name
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 may be imposed by your operating environment.
Tip: You can execute a DATA step without creating a SAS data set. For information, see Suppressing the Output 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.

(data-set-options)
specifies optional arguments that the DATA step applies when it writes observations to the output data set.
See also: Data Set Options for more information.
Featured in: Creating Multiple Data Files and Using Data Set Options

VIEW=view-name
names a view that the DATA step uses to store the input DATA step view.
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

PGM=program-name
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 (/).
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: Storing and Executing a Compiled Program


Details

Suppressing the Output Data Set

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 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. See Creating a Custom Report.

Using Stored Compiled Programs

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 DATA statement uses different syntax to create and store a compiled program and to execute the program.

Action Example
Creating and storing

data sales2/pgm=salerpt;
Executing

data pgm=salerpt;


Examples


Example 1: Creating Multiple Data Files and Using Data Set Options

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.

Example 2: Creating Input DATA Step Views

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;

Example 3: Creating a View and a Data File

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.

Example 4: Storing and Executing a Compiled Program

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;

Example 5: Creating a Custom Report

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;

See Also

Data Set Options


Chapter Contents

Previous

Next

Top of Page

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.