Select a Set of Observations

The WHERE clause conditionally selects observations, within the range specification, according to conditions given in the expression. For example, to list the names of all teenage males in the Sashelp.Class data set, use the following statements:

varNames = {Name Sex Age};
use Sashelp.Class;
list all var varNames where(Sex='M' & Age>12);

Figure 7.9: A Subset of Observations

   OBS Name     Sex       Age                                                   
------ -------- --- ---------                                                   
     1 Alfred   M     14.0000                                                   
     5 Henry    M     14.0000                                                   
     9 Jeffrey  M     13.0000                                                   
    15 Philip   M     16.0000                                                   
    17 Ronald   M     15.0000                                                   
    19 William  M     15.0000                                                   
                                                                                


You can use matrices on the right-hand side of the comparison operator. The following example uses the =* operator to find a string that sounds like or is spelled like certain strings:

list all var varNames where(name=*{"JON","CAROL","JUDI"});

Figure 7.10: Names That Are Close to Specified Strings

   OBS Name     Sex       Age                                                   
------ -------- --- ---------                                                   
     4 Carol    F     14.0000                                                   
     7 Jane     F     12.0000                                                   
    10 John     M     12.0000                                                   
    12 Judy     F     14.0000