Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Working with SAS Data Sets

Specifying a Range of Observations

You can specify a range of observations with a keyword or by record number using the POINT option. You can use the range operand with the data management statements DELETE, FIND, LIST, READ, and REPLACE.

You can specify range using any of the following keywords:

ALL
all observations

CURRENT
the current observation

NEXT < number >
the next observation or next number of observations

AFTER
all observations after the current one

POINT operand
observations by number, where operand can be one of the following:

Operand Example
a single record numberpoint 5
a literal giving several record numberspoint {2 5 10}
the name of a matrix containing record numberspoint p
an expression in parenthesespoint (p+1)
If you want to list all observations in the CLASS data set, use the keyword ALL to indicate that the range is all observations:
   > list all;

           OBS NAME     SEX            AGE    HEIGHT    WEIGHT
        ------ -------- -------- --------- --------- ---------
             1 JOYCE    F          11.0000   51.3000   50.5000
             2 THOMAS   M          11.0000   57.5000   85.0000
             3 JAMES    M          12.0000   57.3000   83.0000
             4 JANE     F          12.0000   59.8000   84.5000
             5 JOHN     M          12.0000   59.0000   99.5000
             6 LOUISE   F          12.0000   56.3000   77.0000
             7 ROBERT   M          12.0000   64.8000  128.0000
             8 ALICE    F          13.0000   56.5000   84.0000
             9 BARBARA  F          13.0000   65.3000   98.0000
            10 JEFFREY  M          13.0000   62.5000   84.0000
            11 CAROL    F          14.0000   62.8000  102.5000
            12 HENRY    M          14.0000   63.5000  102.5000
            13 ALFRED   M          14.0000   69.0000  112.5000
            14 JUDY     F          14.0000   64.3000   90.0000
            15 JANET    F          15.0000   62.5000  112.5000
            16 MARY     F          15.0000   66.5000  112.0000
            17 RONALD   M          15.0000   67.0000  133.0000
            18 WILLIAM  M          15.0000   66.5000  112.0000
            19 PHILIP   M          16.0000   72.0000  150.0000
Without a range specification, the LIST statement lists only the current observation, which in this example is now the last observation because of the previous LIST statement:
   > list;

           OBS NAME     SEX            AGE    HEIGHT    WEIGHT
        ------ -------- -------- --------- --------- ---------
            19 PHILIP   M          16.0000   72.0000  150.0000
Use the POINT keyword with record numbers to list specific observations. You can follow the keyword POINT with a single record number or with a literal giving several record numbers.
   > list point 5;

           OBS NAME     SEX            AGE    HEIGHT    WEIGHT
        ------ -------- -------- --------- --------- ---------
             5 JOHN     M          12.0000   59.0000   99.5000

   > list point {2 4 9};

           OBS NAME     SEX            AGE    HEIGHT    WEIGHT
        ------ -------- -------- --------- --------- ---------
             2 THOMAS   M          11.0000   57.5000   85.0000
             4 JANE     F          12.0000   59.8000   84.5000
             9 BARBARA  F          13.0000   65.3000   98.0000
You can also indicate the range indirectly by creating a matrix containing the records you want listed:
   > p={2 4 9};
   > list point p;

           OBS NAME     SEX            AGE    HEIGHT    WEIGHT
        ------ -------- -------- --------- --------- ---------
             2 THOMAS   M          11.0000   57.5000   85.0000
             4 JANE     F          12.0000   59.8000   84.5000
             9 BARBARA  F          13.0000   65.3000   98.0000
The range operand is usually listed first when you are using the access statements DELETE, FIND, LIST, READ, and REPLACE. Listed below are access statements and their default ranges.

Statement   Default Range
LIST current
READ current
FIND all
REPLACE current
APPEND always at end
DELETE current

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.