Using the READ Statement with the VAR Clause |
Use the READ statement with the VAR clause to read variables from the current SAS data set into column vectors of the VAR clause. Each variable in the VAR clause becomes a column vector with the same name as the variable in the SAS data set. The number of rows is equal to the number of observations processed, depending on the range specification and the WHERE clause. For example, to read the numeric variables AGE, HEIGHT, and WEIGHT for all observations in the CLASS data set, use the following statements:
> read all var {age height weight};
Now use the SHOW NAMES statement to display all the matrices you have created so far in this chapter:
> show names; AGE 19 rows 1 col num 8 HEIGHT 19 rows 1 col num 8 N 1 row 3 cols char 4 P 1 row 3 cols num 8 V 1 row 3 cols char 6 WEIGHT 19 rows 1 col num 8 Number of symbols = 8 (includes those without values)
You see that, with the READ statement, you have created the three numeric vectors AGE, HEIGHT, and WEIGHT. (Notice that the matrices you created earlier, , , and , are also listed.) You can select the variables that you want to access with a VAR clause in the USE statement. The two previous statements can also be written as follows:
use class var{age height weight}; read all;