Chapter Contents
Chapter Contents
Language Reference

EDIT Statement

opens a SAS data set for editing

EDIT SAS-data-set <VAR operand> <WHERE(expression)>
           <NOBS name>;

The inputs to the EDIT statement are as follows:
can be specified with a one-word name (for example, A) or a two-word name (for example, SASUSER.A). For more information on specifying SAS data sets, refer to the chapter on SAS data sets in SAS Language Reference: Concepts.

selects a set of variables.

selects observations conditionally.

names a variable to contain the number of observations.
The EDIT statement opens a SAS data set for reading and updating. If the data set has already been opened, the EDIT statement makes it the current input and output data sets.

You can specify a set of variables to use with the VAR clause, where operand can be specified as one of the following: Below are examples showing each possible way you can use the VAR clause.
   var {time1 time5 time9}; /* a literal giving the variables  */
   var time;                /* a matrix containing the names   */
   var('time1':'time9');    /* an expression                   */
   var _all_;               /* a keyword                       */
The WHERE clause conditionally selects observations, within the range specification, according to conditions given in the clause. The general form of the WHERE clause is

WHERE( variable comparison-op operand)

In the statement above,
is a variable in the SAS data set.

is any one of the following comparison operators:
less than

less than or equal to

equal to

greater than

greater than or equal to

not equal to

contains a given string

does not contain a given string

= :
begins with a given string

= *
sounds like or is spelled similar to a given string

is a literal value, a matrix name, or an expression in parentheses.
WHERE comparison arguments can be matrices. For the following operators, the WHERE clause succeeds if all the elements in the matrix satisfy the condition:

 ^=   ^?   <   <=   >   >=

For the following operators, the WHERE clause succeeds if any of the elements in the matrix satisfy the condition:

 =   ?   = :   = *

Logical expressions can be specified within the WHERE clause using the AND (&) and OR (|) operators. The general form is

 clause&clause (for an AND clause)
 clause|clause (for an OR clause)

where clause can be a comparison, a parenthesized clause, or a logical expression clause that is evaluated using operator precedence.

Note: The expression on the left-hand side refers to values of the data set variables and the expression on the right-hand side refers to matrix values.

The EDIT statement can define a set of variables and the selection criteria that are used to control access to data set observations. The NOBS clause returns the total number of observations in the data set in the variable name.

The VAR and WHERE clauses are optional and can be specified in any order. The NOBS clause is also optional.

See Chapter 6, "Working with SAS Data Sets," for more information on editing SAS data sets.

To edit the data set DAT, or WORK.DAT, use the statements

   edit dat;
   edit work.dat;
To control the variables you want to edit and conditionally select observations for editing, use the VAR and WHERE clauses. For example, to read and update observations for variable I where I is greater than 9, use the statement
   edit work.dat var{i} where (i>9);
Below is an example using the NOBS option.
   /* if MYDATA has 10 observations,                   */
   /* then ct is a numeric matrix with value 10        */
   edit mydata nobs ct;

Chapter Contents
Chapter Contents

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