|
Chapter Contents |
Previous |
Next |
| Language Reference |
reads observations from a data set
The inputs to the READ function are as follows:
Use the READ statement to read variables or records from the current SAS data set into column matrices of the VAR clause or into the single matrix of the INTO clause. When the INTO clause is used, each variable in the VAR clause becomes a column of the target matrix, and all variables in the VAR clause must be of the same type. If you specify no VAR clause, the default variables for the INTO clause are all numeric variables. Read all character variables into a target matrix by using VAR _CHAR_.
You can specify a range of observations with a keyword or by record number using the POINT option. You can use any of the following keywords to specify a range:
| Operand | Example |
| a single record number | point 5 |
| a literal giving several | point {2 5 10} |
| record numbers | |
| the name of a matrix | point p |
| containing record numbers | |
| an expression in parentheses | point (p+1) |
You can specify a set of variables to use with the VAR clause. The operand in the VAR clause can be one of the following:
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
In the statement above,
| = ? < <= > >= |
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.
You can specify ROWNAME= and COLNAME= matrices as part of the INTO clause. The COLNAME= matrix specifies the name of a new character matrix to be created. This COLNAME= matrix is created in addition to the target matrix of the INTO clause and contains variable names from the input data set corresponding to columns of the target matrix. The COLNAME= matrix has dimension 1 ×nvar, where nvar is the number of variables contributing to the target matrix.
The ROWNAME= option specifies the name of a character variable in the input data set. The values of this variable are put in a character matrix with the same name as the variable. This matrix has the dimension nobs×1, where nobs is the number of observations in the range of the READ statement. The range, VAR, WHERE, and INTO clauses are all optional and can be specified in any order.
Row names created via a READ statement are permanently associated with the INTO matrix. You do not need to use a MATTRIB statement to get this association.
For example, to read all observations from the data set variables NAME and AGE, use a READ statement with the VAR clause and the keyword ALL for the range operand. This creates two IML variables with the same names as the data set variables.
read all var{name age};
To read all variables for the 23rd
observation only, use the statement
read point 23;To read the data set variables NAME and ADDR for all observations with a STATE value of
NJ, use the statement
read all var{name addr} where(state="NJ");
See Chapter 6, "Working with SAS Data Sets," for further information.
|
Chapter Contents |
Previous |
Next |
Top |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.