Example 2.2. Ordering the Rows of a Report

Goal

List specific information about selected observations in a data set in a specific order. Group the rows by the values of the ordering variables. Each row in the report should present information for one observation.

Report

                              Listing of Local
 Residential Properties
                                   Price Range
 $200,000 to $350,000
                                           Listed
 by Zone

    Residential        Listing House              
                                    Square
    Zone                 Price Style     Address  
                 Bedrooms Bathrooms   Feet Age
    ----------------------------------------------
----------------------------------------------
    East Lake         $329,900 ranch     8122
 Maude Steward Rd.           3       3.0  2,400   2
                      $281,900 split     6424 Old
 Jenks Rd.               3       1.5  1,225  18
                      $260,000 split     4341 Rock
 Quarry                 3       1.0  1,010  28
                      $207,900 ranch     6509
 Orchard Knoll               3       2.0  1,526   6

    Ensley            $260,000 townhouse 409
 Galashiels                   2       1.5  1,280   4

    Inside Beltline   $343,000 capecod   100
 Cumberland Green             3       2.5  1,650   0
                      $284,000 townhouse 765
 Crabtree Crossing            3       2.0  1,471   1
                      $279,950 split     101
 Meadowglade Ln.              3       2.0  2,004   0
                      $279,900 townhouse 108
 Chattle Close                3       2.5  2,080   4
                      $259,900 townhouse 216
 Concannon Ct.                2       1.5  1,040   9
                      $249,900 townhouse 1239
 Donaldson Ct.               2       1.5  1,150  15

    Mountain Brook    $200,000 duplex    108 South
 Elm St.                3       1.0  1,569  73

    North Ridge       $344,500 bungalow  6008
 Brass Lantern Ct.           3       2.5  2,416   6
                      $314,900 colonial  4000
 Skipjack Ct.                3       2.5  2,750   0
                      $285,000 split     2414 Van
 Dyke                    3       1.0  1,245  36
                      $282,900 split     500 E.
 Millbrook Rd.             3       1.5  1,329  23
                      $200,000 split     6324
 Lakeland, Lake Park         3       2.0  1,662  12

    Roebuck           $323,500 split     110
 Skylark Way                  3       2.0  1,976  10
                      $286,900 split     5617
 Laurel Crest Dr.            3       1.5  1,441  28
                      $271,000 townhouse 8
 Stonevillage                   2       2.0  1,276   6

    Southside         $202,000 townhouse 154
 Montrose                     2       2.0  1,595   6

    Westend           $278,900 split     Rt.5
 Yarbororugh Rd.             2       1.0    960   2
                      $217,800 split     603
 Greentree Dr.                3       2.0  1,533   5


                                   Listing
 Produced on Dec 10, 2005


Example Features

Data SetHOUSING
Featured StepPROC REPORT
Featured Step Statements and OptionsDEFINE statement: ORDER option

WHERE statement

BREAK AFTER statement
Formatting FeaturesPROC REPORT statement: SPLIT= option PROC REPORT statement: HEADLINE, SPACING=, and WIDTH= options when sending output to the LISTING destination
Additional FeaturesMacro functions
Related TechniquePROC SORT and PROC PRINT
A Closer LookComparing PROC PRINT and PROC REPORT
ODS Enhanced Version of this ExampleExample 6.1
Other Examples That Use This Data SetExamples 2.1 and 6.1

Example Overview

This detail report lists specific data about houses for sale within the price range of $200,000 to $350,000 and is similar to Example 2.1. This report, however, does not require that you sort the data set prior to producing the report. Statements within PROC REPORT order the rows first by residential zone and then within each residential zone, by descending price.

Each row in the report corresponds to one observation in the HOUSING data set. Each column corresponds to one variable.

Program

Create a format to associate meaningful descriptions to the numeric values of the variable ZONE.
proc format;
  value $zonefmt '1'='North Ridge'
                 '2'='Inside Beltline'
                 '3'='Southside'
                 '4'='East Lake'
                 '5'='Westend'
                 '6'='Mountain Brook'
                 '7'='Ensley'
                 '8'='Roebuck';
run;

proc report data=housing

Send output to the SAS procedure output destination rather than the interactive REPORT window.
     nowindows

Specify the split character to control line breaks in column headings.
     split='/'

Underline all column headers and the spaces between them when sending output to the LISTING destination.
     headline

Override the default spacing of two blank characters between columns when sending output to the LISTING destination.
       spacing=1;

   title 'Listing of Local Residential Properties';
   title2 'Price Range $200,000 to $350,000';
   title3 'Listed by Zone';

Include today’s date in the footnote text. Place double quotes around the footnote text so that the macro function obtains today’s date and formats it.
   footnote "Listing Produced on
            %sysfunc(today(),worddate12.)";

Select the observations to include in the report.
   where price between 200000 and 350000;

List the columns in the order in which they should appear in the report.
   column zone price type address bedr bath sqfeet
 age;

Describe the order of the rows and specify formats (FORMAT=), column widths (WIDTH=), and column headings (text enclosed in single quotes). Order the detail rows first by the formatted value of ZONE and within each ZONE, order the detail rows in descending order by PRICE. Include the forward slash (/) in the column heading so that SAS inserts a line break in the column heading at the position of the forward slash. Specify the column width when sending output to the LISTING destination.
   define zone     / order format=$zonefmt15.
                     width=15
                     'Residential/Zone';
   define price    / order descending
                     format=dollar10. width=10
                     'Listing/Price';

   define type     / display
                     format=$9.'House/Style';

   define address  / format=$25. width=25 'Address';
   define bedr     / format=2. width=8 'Bedrooms';
   define bath     / format=3.1 width=9 'Bathrooms';
   define sqfeet   / format=comma6. width=6
                     'Square/Feet';
   define age      / format=3. 'Age';

Write a blank line after the last row for each unique value of the order variable ZONE.
   break after zone / skip;
run;


Related Technique

A report similar to the one featured above can be produced with PROC SORT and PROC PRINT as demonstrated in this section. Figure 2.2 presents the output from a program that uses PROC SORT and PROC PRINT.

Figure 2.2. Output Produced by PROC PRINT
                            Listing of Local Residential Properties
                               Price Range $200,000 to $350,000
                                       Listed by Zone

                  House                                                 Square         Listing
  Zone            Style     Address                  Bedrooms Bathrooms  Feet  Age       Price

  North Ridge     bungalow  6008 Brass Lantern Ct.       3       2.5     2,416   6    $344,500
                  colonial  4000 Skipjack Ct.            3       2.5     2,750   0    $314,900
                  split     500 E. Millbrook Rd.         3       1.5     1,329  23    $282,900
                  split     2414 Van Dyke                3       1.0     1,245  36    $285,000
                  split     6324 Lakeland, Lake Park     3       2.0     1,662  12    $200,000

  Inside Beltline capecod   100 Cumberland Green         3       2.5     1,650   0    $343,000
                  split     101 Meadowglade Ln.          3       2.0     2,004   0    $279,950
                  townhouse 1239 Donaldson Ct.           2       1.5     1,150  15    $249,900
                  townhouse 216 Concannon Ct.            2       1.5     1,040   9    $259,900
                  townhouse 765 Crabtree Crossing        3       2.0     1,471   1    $284,000
                  townhouse 108 Chattle Close            3       2.5     2,080   4    $279,900

  Southside       townhouse 154 Montrose                 2       2.0     1,595   6    $202,000

  East Lake       ranch     6509 Orchard Knoll           3       2.0     1,526   6    $207,900
                  ranch     8122 Maude Steward Rd.       3       3.0     2,400   2    $329,900
                  split     4341 Rock Quarry             3       1.0     1,010  28    $260,000
                  split     6424 Old Jenks Rd.           3       1.5     1,225  18    $281,900

  Westend         split     Rt.5 Yarbororugh Rd.         2       1.0       960   2    $278,900
                  split     603 Greentree Dr.            3       2.0     1,533   5    $217,800

  Mountain Brook  duplex    108 South Elm St.            3       1.0     1,569  73    $200,000

  Ensley          townhouse 409 Galashiels               2       1.5     1,280   4    $260,000

  Roebuck         split     5617 Laurel Crest Dr.        3       1.5     1,441  28    $286,900
                  split     110 Skylark Way              3       2.0     1,976  10    $323,500
                  townhouse 8 Stonevillage               2       2.0     1,276   6    $271,000


                               Listing Produced on Dec 10, 2005

The program that produced the report in Figure 2.2 follows.

Ensure that the BYLINE option is in effect when executing this program. This will keep information for multiple zones on the same page. If NOBYLINE is in effect, PROC PRINT starts a new page for each value of the BY variable, ZONE. For more about the BYLINE option, see Example 2.3.

Use the same format as shown in the main example.
proc format;
  value $zonefmt '1'='North Ridge'
                 '2'='Inside Beltline'
                 '3'='Southside'
                 '4'='East Lake'
                 '5'='Westend'
                 '6'='Mountain Brook'
                 '7'='Ensley'
                 '8'='Roebuck';
run;

proc sort data=housing;
   by zone type;
run;
proc print data=housing

Ensure that the layout on each page of a multipage report is the same when sending output to the LISTING destination.
     uniform

Define the split character for column headings.
     split='/';

  title 'Listing of Local Residential Properties';
  title2 'Price Range $200,000 to $350,000';
  title3 'Listed by Zone';

  footnote "Listing Produced on
            %sysfunc(today(),worddate12.)";

   where price between 200000 and 350000;
   by zone;

Specify on the ID and VAR statements the variables to include in the report and their order of appearance. Suppress the default observation number column and replace it with the values of the variable named on the ID statement. To list the ID variable only once for each BY group and suppress the usual headings above each BY group, specify the same variable on both the BY statement and ID statement.
   id zone;
   var type address bedr bath sqfeet age price;

   format sqfeet comma6. price dollar10. zone
          $zonefmt15.;

   label zone='Zone'
         type='House/Style'
         address='Address'
         bedr='Bedrooms'
         bath='Bathrooms'
         sqfeet='Square/Feet'
         age='Age'
         price='Listing/Price';
run;


If you want to send the report to the LISTING destination, you can achieve the look of underlining in the headings. Revise the LABEL statement as follows to include the split character followed by dashes.

     label zone='Zone/---------------'
           type='House/Style/--------'
           address='Address/-------------------------'
           bedr='Bedrooms/--------'
           bath='Bathrooms/---------'
           sqfeet='Square/Feet/------'
           age='Age/---'
           price='Listing/Price/----------';

The revised LABEL statement causes the headings to appear as if they are underlined, as shown below in the following partial listing of the report.

                            Listing of Local
 Residential Properties
                               Price Range $200
,000 to $350,000
                                        Listed by Zone

                 House                            
                      Square      Listing
      Zone       Style              Address       
   Bedrooms Bathrooms  Feet  Age   Price
 --------------- -------- 
 ------------------------- -------- ---------
 ------ --- ----------

 North Ridge     bungalow  6008 Brass Lantern Ct. 
       3       2.5     2,416   6   $344,500
                 colonial  4000 Skipjack Ct.      
       3       2.5     2,750   0   $314,900
                 split     2414 Van Dyke          
       3       1.0     1,245  36   $285,000
                 split     500 E. Millbrook Rd.   
       3       1.5     1,329  23   $282,900
                 split     6324 Lakeland, Lake
 Park      3       2.0     1,662  12   $200,000


A Closer Look

Comparing PROC PRINT and PROC REPORT

The two reports in this example are similar. The processing of the two procedures REPORT and PRINT can differ. The differences are highlighted in Table 2.2.

Table 2.2. Comparing PROC PRINT and PROC REPORT
FeaturePROC PRINTPROC REPORT
Ordering rowsAlways orders variables by their internal values (in this case, it orders the numbers 1 to 8). You must sort the input data set and use a BY statement in the PROC PRINT step.Gives you control over the order of the rows with the ORDER and the ORDER= options. Sorting is unnecessary. By default, PROC REPORT orders variables by their formatted values.
Printing repeated rowsPrints the value of every variable on every row of the report unless the variable is listed in both the BY and ID statements.Does not repeat the value of an order or group variable from one row to the next if the value is the same.
Placing values and column headersAutomatically places values and column headers.Right-aligns numeric values and their column headers and left-aligns character values and their column headers by default. You can control the alignment with options in the DEFINE statement.
Underlining column headers (applies only to the LISTING destination)Requires hard-coding the underlining in the labels of the column headers.Uses one option (HEADLINE) to underline all column headers.

Where to Go from Here

BY statement processing. See “BY Statement” in the “Statements” section of SAS 9.1 Language Reference: Dictionary, and “Statements with the Same Function in Multiple Procedures” in the “Concepts” section of Base SAS 9.1 Procedures Guide.

PROC PRINT reference, usage information, and additional examples. See “The PRINT Procedure” in the “Procedures” section of Base SAS 9.1 Procedures Guide.

PROC REPORT reference, usage information, and additional examples. See “The REPORT Procedure” in the “Procedures” section of Base SAS 9.1 Procedures Guide.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.151.21