Working with SAS Data Sets


Specify a Range of Observations

You can specify a range of observations with a keyword or by record number by using the POINT option. For example, if you want to list all observations in the Sashelp.Class data set, use the ALL keyword to indicate that the range is all observations, as shown in the following example:

use Sashelp.Class;
list all;

Figure 7.5: All Observations

   OBS Name     Sex       Age    Height    Weight                               
------ -------- --- --------- --------- ---------                               
     1 Alfred   M     14.0000   69.0000  112.5000                               
     2 Alice    F     13.0000   56.5000   84.0000                               
     3 Barbara  F     13.0000   65.3000   98.0000                               
     4 Carol    F     14.0000   62.8000  102.5000                               
     5 Henry    M     14.0000   63.5000  102.5000                               
     6 James    M     12.0000   57.3000   83.0000                               
     7 Jane     F     12.0000   59.8000   84.5000                               
     8 Janet    F     15.0000   62.5000  112.5000                               
     9 Jeffrey  M     13.0000   62.5000   84.0000                               
    10 John     M     12.0000   59.0000   99.5000                               
    11 Joyce    F     11.0000   51.3000   50.5000                               
    12 Judy     F     14.0000   64.3000   90.0000                               
    13 Louise   F     12.0000   56.3000   77.0000                               
    14 Mary     F     15.0000   66.5000  112.0000                               
    15 Philip   M     16.0000   72.0000  150.0000                               
    16 Robert   M     12.0000   64.8000  128.0000                               
    17 Ronald   M     15.0000   67.0000  133.0000                               
    18 Thomas   M     11.0000   57.5000   85.0000                               
    19 William  M     15.0000   66.5000  112.0000                               
                                                                                



If you do not explicitly specify a range of observations, the LIST statement displays the current observation. Because of the previous LIST statement, the current observation for the Sashelp.Class data is the last observation, as shown in FigureĀ 7.6:

list;

Figure 7.6: Current Observation

   OBS Name     Sex       Age    Height    Weight                               
------ -------- --- --------- --------- ---------                               
    19 William  M     15.0000   66.5000  112.0000                               
                                                                                



To display a specific set of observations, use the POINT keyword and specify a vector of observation numbers, as shown in the following statement:

p = {3 6 9};
list point p;

Figure 7.7: Other Observations

   OBS Name     Sex       Age    Height    Weight                               
------ -------- --- --------- --------- ---------                               
     3 Barbara  F     13.0000   65.3000   98.0000                               
     6 James    M     12.0000   57.3000   83.0000                               
     9 Jeffrey  M     13.0000   62.5000   84.0000