Previous Page | Next Page

Working with SAS Data Sets

Using the READ Statement with the WHERE Clause

Use the WHERE clause as you did with the LIST statement, to conditionally select observations from within the specified range. If you want to create a matrix FEMALE that contains the variables AGE, HEIGHT, and WEIGHT for females only, use the following statements:

   > read all var _num_ into female where(sex="F");
   > print female;

                    FEMALE
                        11      51.3      50.5
                        12      59.8      84.5
                        12      56.3        77
                        13      56.5        84
                        13      65.3        98
                        14      62.8     102.5
                        14      64.3        90
                        15      62.5     112.5
                        15      66.5       112

Now try some special features of the WHERE clause to find values that begin with certain characters (the =: operator) or that contain certain strings (the ? operator). To create a matrix that contains the students whose names begin with the letter "J," use the following statements:

   > read all var{name} into j where(name=:"J");
   > print j;

                                J
                                JOYCE
                                JAMES
                                JANE
                                JOHN
                                JEFFREY
                                JUDY
                                JANET

To create a matrix of children with names that contains the string "AL," use the following statement:

   > read all var{name} into al where(name?"AL");
   > print al;

                                 AL
                                 ALICE
                                 ALFRED
                                 RONALD
Previous Page | Next Page | Top of Page