Previous Page | Next Page

Working with SAS Data Sets

Selecting a Set of Variables

You can use the VAR clause to select a set of variables. The general form of the VAR clause is as follows:

VAR operand ;

where operand can be specified by using one of the following items:

  • a literal that contains variable names

  • the name of a matrix that contains variable names

  • an expression in parentheses yielding variable names

  • one of the following keywords:

    _ALL_

    for all variables

    _CHAR_

    for all character variables

    _NUM_

    for all numeric variables

The following examples show all possible ways you can use the VAR clause:

  var {time1 time5 time9};  /* a literal giving the variables   */
  var time;                 /* a matrix that contains the names */
  var('time1':'time9');     /* an expression                    */
  var _all_;                /* a keyword                        */

For example, to list students’ names from the CLASS data set, use the VAR clause with a literal, as in the following statement:

   > list point p var{name};

                OBS NAME
             ------ --------
                  2 THOMAS
                  4 JANE
                  9 BARBARA

To list AGE, HEIGHT, and WEIGHT, you can use the VAR clause with a matrix giving the variables, as in the following statements:

   > v={age height weight};
   > list point p var v;

              OBS       AGE    HEIGHT    WEIGHT
           ------ --------- --------- ---------
                2   11.0000   57.5000   85.0000
                4   12.0000   59.8000   84.5000
                9   13.0000   65.3000   98.0000

The VAR clause can be used with the following statements for the tasks described:

Statement

VAR Clause Function

APPEND

specifies which IML variables contain data to append to the data set

CREATE

specifies the variables to go in the data set

EDIT

limits which variables are accessed

LIST

specifies which variables to list

READ

specifies which variables to read

REPLACE

specifies which data set variable’s data values to replace with corresponding IML variable data values

USE

limits which variables are accessed

Previous Page | Next Page | Top of Page