Chapter Contents

Previous

Next
SAS Language Reference: Dictionary

DATA Step Statements


Executable and Declarative Statements

DATA step statements are those that can appear in the DATA step. They can be either executable or declarative. Executable statements result in some action during individual iterations of the DATA step; declarative statements supply information to SAS and take effect when the system compiles program statements.

The following tables show the SAS executable and declarative statements that you can use in the DATA step.

Executable Statements in the DATA Step
Executable Statements

ABORT IF, Subsetting
PUT
assignment IF-THEN/ELSE
PUT, Column
CALL INFILE
PUT, Formatted
CONTINUE INPUT
PUT, List
DELETE INPUT, Column
PUT, Named
DISPLAY INPUT, List
REDIRECT
DO INPUT, Named
REMOVE
DO, Iterative LEAVE
REPLACE
DO Until LINK
RETURN
DO While LIST
SELECT
ERROR LOSTCARD
SET
FILE MERGE
STOP
FILE, ODS Null
Sum
GO TO OUTPUT
UPDATE

Declarative Statements in the DATA Step
Declarative Statements

ARRAY DATALINES
LABEL
Array Reference DATALINES4
Labels, Statement
ATTRIB DROP
LENGTH
BY END
RENAME
CARDS FORMAT
RETAIN
CARDS4 INFORMAT
WHERE
DATA KEEP
WINDOW


DATA Step Statements by Category

In addition to being either executable or declarative, SAS DATA step statements can be grouped into four categories, depending on their function.

Categories of DATA Step Statements
Statements in this category . . . let you . . .
ACTION

CONTROL

FILE-HANDLING


INFORMATION



The following table lists and briefly describes the DATA step statements by category.

Categories and Descriptions of DATA Step Statements
Category Statement Description
Action ABORT
Stops executing the current DATA step, SAS job, or SAS session

Assignment
Evaluates an expression and stores the result in a variable

CALL
Invokes or calls a SAS CALL routine

DELETE
Stops processing the current observation

ERROR
Sets _ERROR_ to 1 and, optionally, writes a message to the SAS log

IF, Subsetting
Continues processing only those observations that meet the condition

LIST
Writes to the SAS log the input data records for the observation that is being processed

LOSTCARD
Resynchronizes the input data when SAS encounters a missing or invalid record in data that have multiple records per observation

Null
Signals the end of data lines; acts as a placeholder*

OUTPUT
Writes the current observation to a SAS data set

REDIRECT
Points to different input or output SAS data sets when you execute a stored program

REMOVE
Deletes an observation from a SAS data set

REPLACE
Replaces an observation in the same location

STOP
Stops execution of the current DATA step

Sum
Adds the result of an expression to an accumulator variable

WHERE
Selects observations from SAS data sets that meet a particular condition
Control CONTINUE
Stops processing the current DO-loop iteration and resumes with the next iteration

DO
Designates a group of statements to be executed as a unit

DO, Iterative
Executes statements between DO and END repetitively based on the value of an index variable

DO UNTIL
Executes statements in a DO loop repetitively until a condition is true

DO WHILE
Executes statements repetitively while a condition is true

END
Ends a DO group or a SELECT group

GO TO
Moves execution immediately to the statement label that is specified

IF-THEN/ELSE
Executes a SAS statement for observations that meet specific conditions

Labels, Statement
Identifies a statement that is referred to by another statement

LEAVE
Stops processing the current loop and resumes with the next statement in sequence

LINK
Jumps to a statement label

RETURN
Stops executing statements at the current point in the DATA step and returns to a predetermined point in the step

SELECT
Executes one of several statements or groups of statements
File-handling BY
Controls the operation of a SET, MERGE, MODIFY, or UPDATE statement in the DATA step and sets up special grouping variables

CARDS
Indicates that data lines follow

CARDS4
Indicates that data lines that contain semicolons follow

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

DATALINES
Indicates that data lines follow

DATALINES4
Indicates that data lines that contain semicolons follow

FILE
Specifies the current output file for PUT statements

FILE, ODS
Defines the structure of the data component that holds the results of the DATA step and binds that component to a template to produce an output object. ODS sends this object to all open ODS destinations, each of which formats the object appropriately. Also controls what happens when the PUT statement tries to write past the end of a line.

INFILE
Identifies an external file to read with an INPUT statement

INPUT
Describes the arrangement of values in the input data record and assigns input values to the corresponding SAS variables

INPUT, Column
Reads input values from specified columns and assigns them to the corresponding SAS variables

INPUT, Formatted
Reads input values with specified informats and assigns them to the corresponding SAS variables

INPUT, List
Scans the input data record for input values and assigns them to the corresponding SAS variables

INPUT, Named
Reads data values that appear after a variable name that is followed by an equal sign and assigns them to corresponding SAS variables

MERGE
Joins observations from two or more SAS data sets into single observations

MODIFY
Replaces, deletes, and appends observations in an existing SAS data set in place; does not create an additional copy

PUT
Writes lines to the SAS log, to the SAS procedure output file, or to an external file that is specified in the most recent FILE statement

PUT, Column
Writes variable values in the specified columns in the output line

PUT, Formatted
Writes variable values with the specified format in the output line

PUT, List
Writes variable values and the specified character strings in the output line

PUT, Named
Writes variable values after the variable name and an equal sign

PUT, _ODS_
Writes data values to a special buffer from which they can be written to the data component, and formatted by ODS destinations

SET
Reads an observation from one or more SAS data sets

UPDATE
Updates a master file by applying transactions
Information ARRAY
Defines elements of an array

Array Reference
Describes the elements in an array to be processed

ATTRIB
Associates a format, informat, label, and/or length with one or more variables

DROP
Excludes variables from output SAS data sets

FORMAT
Associates formats with variables

INFORMAT
Associates informats with variables

KEEP
Includes variables in output SAS data sets

LABEL
Assigns descriptive labels to variables

LENGTH
Specifies the number of bytes for storing variables

MISSING
Assigns characters in your input data to represent special missing values for numeric data

RENAME
Specifies new names for variables in output SAS data sets

RETAIN
Causes a variable that is created by an INPUT or assignment statement to retain its value from one iteration of the DATA step to the next


FOOTNOTE 1:   * Because it can be branched to, the null statement is considered an executable statement in the DATA step. However, the null statement can appear anywhere in a SAS program. [arrow]


Chapter Contents

Previous

Next

Top of Page

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