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:
SAS-data-set
can be specified with a one-level name (for example, A) or a two-level name (for example, SASUSER.A). For more information about specifying SAS data sets, refer to the chapter on SAS data sets in SAS Language Reference: Concepts.

operand
selects a set of variables.

expression
selects observations conditionally.

name
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:

The following examples demonstrate 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 preceding statement,
variable
is a variable in the SAS data set.

comparison-op
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 like a given string

operand
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 by 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 by 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 for more information on editing SAS data sets.

To edit the data set DAT, or WORK.DAT, use the following 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 following statement:
  
    edit work.dat var{i} where (i>9);
 
The following example uses the NOBS option:
  
    /* if MYDATA has 10 observations,                   */ 
    /* then ct is a numeric matrix with value 10        */ 
    edit mydata nobs ct;
 

Previous Page | Next Page | Top of Page