Language Reference |
EDIT Statement |
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.
The arguments to the EDIT statement are as follows:
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, see 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.
You can specify a set of variables to use with the VAR clause, where operand can be specified as one of the following:
a literal that contains variable names
the name of a matrix that contains variable names
an expression in parentheses that yields variable names
one of the keywords described in the following list:
for all variables
for all character variables
for all numeric variables
The following examples demonstrate each possible way you can use the VAR clause:
var {x1 x5 x9}; /* a literal matrix of names */ var x; /* a matrix that contains the names */ var("x1":"x9"); /* 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
The arguments to the WHERE clause are as follows:
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 like 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 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 7 for more information about editing SAS data sets.
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 which the Age variable is greater than 30, use the following statements:
proc iml; /* create sample data set */ sex = { M, M, M, F, F, F}; age = {34, 28, 38, 32, 24, 18}; create MyData var {"Sex" "Age"}; append; close MyData; edit MyData where (Age>30); list all; close MyData;
To edit the data set Work.MyData and obtain the number of observations in the data set, use the following statements:
edit Work.MyData nobs NumObs; close Work.MyData; print NumObs;
Another example of using the EDIT statement is presented in the documentation for the DELETE statement.
Copyright © SAS Institute, Inc. All Rights Reserved.