Example 2.3. Placing Data That Is Constant for a Category in Titles

Goal

Order a data set by categories and list the observations. Write information that is constant for a category in the page titles rather than in columns. Each row in the report presents information about one observation.

Report

Project FeederWatch Counts for Ten Observation
 Periods in Minnesota during 2002-2003
Counts for Site MN1001
Site Description: Medium (1,001-4,000 sq ft
/101-375 sq m) in landscaped yard (with lawn and
 plantings)
Community: Rural with a population of 5,001 to 25,000

                           Ever
Species                    Seen    P1    P2    P3 
   P4    P5    P6    P7    P8    P9     P10

American crow              ****     0     0     0 
    1     2     0     2     0     0       0
American goldfinch         ****     2     2     3 
    6     9     7     6     8     7       6
American robin             ****     1    20     1 
    0     0     0     1     0     0       3
American tree sparrow               0     0     0 
    0     0     0     0     0     0       0
Black-capped chickadee     ****     3     2     2 
    2     1     1     2     2     1       2
Blue jay                   ****     2     2     1 
    4     2     2     1     4     3       2
Boreal chickadee                    0     0     0 
    0     0     0     0     0     0       0
Brown creeper                       0     0     0 
    0     0     0     0     0     0       0
Chipping sparrow           ****     0     0     0 
    0     0     0     0     0     1       0
Common grackle             ****     0     0     0 
    0     0     0     0     0     0       5
Common redpoll                      0     0     0 
    0     0     0     0     0     0       0
Cooper's hawk                       0     0     0 
    0     0     0     0     0     0       0
Dark-eyed junco            ****     1     9     1 
    2     3     2     5     2    20       4
Downy woodpecker           ****     3     2     2 
    2     3     3     6     3     4       6
European starling          ****     0     0     0 
    0     0     0     0     0     4       5
Fox sparrow                         0     0     0 
    0     0     0     0     0     0       0
Hairy woodpecker           ****     0     0     1 
    3     2     2     1     0     1       1
House finch                ****     3     0     0 
    0     0     0     0     0     2       2
House sparrow              ****    20    30    20 
   20    20    20    20    20    10      20
Loggerhead shrike                   0     0     0 
    0     0     0     0     0     0       0
Mallard                             0     0     0 
    0     0     0     0     0     0       0
Mourning dove              ****     0     0     0 
    0     0     0     0     1     0       1
Northern cardinal          ****     2     2     0 
    1     3     2     2     2     3       2
Norther flicker            ****     0     0     0 
    0     0     0     0     2     0       0
Northern shrike                     0     0     0 
    0     0     0     0     0     0       0
Pileated woodpecker        ****     0     0     0 
    1     1     0     0     1     0       0
Pine siskin                         0     0     0 
    0     0     0     0     0     0       0
Purple finch               ****     1     0     0 
    0     0     0     0     0     0       0
Red-breasted nuthatch               0     0     0 
    0     0     0     0     0     0       0
Reb-bellied woodpecker     ****     0     1     1 
    1     1     1     1     1     1       1
Red-winged blackbird                0     0     0 
    0     0     0     0     0     0       0
Rock dove                           0     0     0 
    0     0     0     0     0     0       0
Sharp-shinned hawk                  0     0     0 
    0     0     0     0     0     0       0
Song sparrow               ****     0     0     0 
    0     0     0     1     0     0       0
Tufted titmouse                     0     0     0 
    0     0     0     0     0     0       0
White-breasted nuthatch    ****     2     1     1 
    1     1     1     2     1     2       1
White-throated sparrow              0     0     0 
    0     0     0     0     0     0       0

Key to Ten Observation Periods:
 1: 09nov2002-22nov2002   2: 23nov2002-06dec2002 
 3: 07dec2002-20dec2002  4: 21dec2002-03jan2003
 5: 04jan2003-17jan2003   6: 18jan2003-31jan2003 
 7: 01feb2003-14feb2003  8: 15feb2003-28feb2003
 9: 01mar2003-14mar2003  10: 15mar2003-28mar2003


Project FeederWatch Counts for Ten Observation
 Periods in Minnesota during 2002-2003
Counts for Site MN1002
Site Description: Medium (1,001-4,000 sq ft
/101-375 sq m) in landscaped yard (with lawn and
 plantings)
Community: Rural with a population of 1 to 5,000

                           Ever
Species                    Seen    P1    P2    P3 
   P4    P5    P6    P7    P8    P9     P10

American crow              ****     0     0     0 
    0     0     0     0     2     2       1
American goldfinch         ****     1     0     0 
    2     7     0     1     7     7       0
American robin             ****     0     0     0 
    0     0     0     0     1     0       0
American tree sparrow               0     0     0 
    0     0     0     0     0     0       0
Black-capped chickadee     ****     3     3     4 
    4     5     5     4     4     6       4
Blue jay                   ****     2     2     2 
    1     2     2     0     4     2       1
Boreal chickadee                    0     0     0 
    0     0     0     0     0     0       0
Brown creeper              ****     1     3     2 
    2     1     3     1     2     2       1
Chipping sparrow                    0     0     0 
    0     0     0     0     0     0       0
Common grackle             ****     2     1     2 
    1     0     0     0     0     0       0
Common redpoll                      0     0     0 
    0     0     0     0     0     0       0
Cooper's hawk              ****     0     0     1 
    0     0     0     0     0     0       0
Dark-eyed junco            ****    30     6     1 
   12     6     6     0     4     8       0
Downy woodpecker           ****     1     2     2 
    2     1     1     1     2     2       2
European starling          ****     0     0     0 
    0     4     1     0     1     0       3
Fox sparrow                         0     0     0 
    0     0     0     0     0     0       0
Hairy woodpecker           ****     0     0     0 
    1     1     0     0     1     1       1
House finch                ****     1     8     0 
    6     6     8     0     8     8       2
House sparrow              ****    40    50    50 
   50    50    50    50    25    30      20
Loggerhead shrike                   0     0     0 
    0     0     0     0     0     0       0
Mallard                             0     0     0 
    0     0     0     0     0     0       0
Mourning dove              ****     0     0     0 
    0     0     0     0     2     2       2
Northern cardinal          ****     2     1     1 
    1     2     2     1     2     2       1
Norther flicker            ****     1     1     0 
    1     1     1     0     1     0       2
Northern shrike                     0     0     0 
    0     0     0     0     0     0       0
Pileated woodpecker                 0     0     0 
    0     0     0     0     0     0       0
Pine siskin                ****     1     0     0 
    0     0     0     0     0     0       0
Purple finch                        0     0     0 
    0     0     0     0     0     0       0
Red-breasted nuthatch      ****     0     0     1 
    0     0     0     0     0     0       0
Reb-bellied woodpecker     ****     1     1     1 
    1     1     0     1     1     1       2
Red-winged blackbird       ****     0     0     0 
    0     0     0     0     0     0       1
Rock dove                           0     0     0 
    0     0     0     0     0     0       0
Sharp-shinned hawk         ****     1     1     0 
    1     0     0     0     1     1       0
Song sparrow                        0     0     0 
    0     0     0     0     0     0       0
Tufted titmouse                     0     0     0 
    0     0     0     0     0     0       0
White-breasted nuthatch    ****     3     3     3 
    2     2     3     2     3     3       2
White-throated sparrow     ****    24     0     0 
    0     0     0     0     0     0       0

Key to Ten Observation Periods:
 1: 09nov2002-22nov2002   2: 23nov2002-06dec2002 
 3: 07dec2002-20dec2002  4: 21dec2002-03jan2003
 5: 04jan2003-17jan2003   6: 18jan2003-31jan2003 
 7: 01feb2003-14feb2003  8: 15feb2003-28feb2003
 9: 01mar2003-14mar2003  10: 15mar2003-28mar2003


Example Features

Data SetFEEDERBIRDS
Featured StepPROC PRINT
Featured Step Statements and OptionsPROC PRINT statement: LABEL option BY statement
Formatting FeaturesOPTIONS statement: BYLINE/NOBYLINE, MISSING, and CENTER options TITLE statement with #BYVAL
A Closer LookWorking with #BYVAL, #BYVAR, and #BYLINE when Customizing Titles

Example Overview

When you want to list the observations in a data set by categories, and the values of several of the variables for a category are constant, you can place the constant information in the titles. By doing so, you make more room on the report page for information that varies within a category.

This example lists observations from the FEEDERBIRDS data set. This data set is a random sample of observations taken from a Cornell Laboratory of Ornithology data set that manages the records in the Project FeederWatch Citizen Science program. The sample contains records of the bird species seen and numbers counted at bird feeders during the 2002-2003 winter season in Minnesota.

Each observation in the data set corresponds to the maximum number of birds of one species seen at one time during ten observation periods. The data set is ordered by site ID. Several characteristics of the site are stored in the data set. These descriptions are constant for each site and their values are printed in the titles of the report. The program uses the #BYVAL feature of the TITLE statement in conjunction with the SAS system option NOBYLINE to place the site characteristics in the titles. The NOBYLINE option suppresses the BY line that normally appears in output produced with BY-group processing,

PROC PRINT lists the observations in the FEEDERBIRDS data set. If you use the BY statement and the NOBYLINE option, PROC PRINT always starts a new page for each BY group. This behavior ensures that if you create customized BY lines by putting BY-group information in a title and you suppress the default BY lines with NOBYLINE, the information in the titles matches the report on the pages.

The report that follows lists the counts for two of the ten sites in the sample data set.

Program

Suppress the automatic printing of BY lines in subsequent procedure output because the #BYVAL feature will be used to list BY-group data.
options nobyline

Left-align SAS procedure output.
        nocenter

Assign ‘0’ as the character to print for missing numeric values.
        missing='0';

proc format;
  value size
   1='Very small -- a window or hanging feeder only'
   2='Small (< 1,000 sq ft/100 sq m)'
   3='Medium (1,001-4,000 sq ft/101-375 sq m)'
   4='Large (> 4,000 sq ft/375 sq m)';
  value desc
    1='no vegetation (pavement only)'
    2='garden or courtyard'
    3='mix of natural and landscaped vegetation'
    4='landscaped yard (with lawn and plantings)'
    5='natural vegetation (woods, fields)'
    6='desert: natural or landscaped'
    7='other type';
  value pop 1='1 to 5,000'
            2='5,001 to 25,000'
            3='25,001 to 100,000'
            4='More than 100,000';
 value dens 1='Rural'
            2='Rural/suburban mix'
            3='Suburban'
            4='Urban';
 value $species 'amecro'='American crow'
                'amegfi'='American goldfinch'
                'amerob'='American robin'
                'amtspa'='American tree sparrow'
                'bkcchi'='Black-capped chickadee'
                'blujay'='Blue jay'
                'borchi'='Boreal chickadee'
                'brncre'='Brown creeper'
                'chispa'='Chipping sparrow'
                'comgra'='Common grackle'
                'comred'='Common redpoll'
                'coohaw'='Cooper''s hawk'
                'daejun'='Dark-eyed junco'
                'dowwoo'='Downy woodpecker'
                'eursta'='European starling'
                'foxspa'='Fox sparrow'
                'haiwoo'='Hairy woodpecker'
                'houfin'='House finch'
                'houspa'='House sparrow'
                'logshr'='Loggerhead shrike'
                'mallar'='Mallard'
                'moudov'='Mourning dove'
                'norcar'='Northern cardinal'
                'norfli'='Norther flicker'
                'norshr'='Northern shrike'
                'pilwoo'='Pileated woodpecker'
                'pinsis'='Pine siskin'
                'purfin'='Purple finch'
                'rebnut'='Red-breasted nuthatch'
                'rebwoo'='Reb-bellied woodpecker'
                'rewbla'='Red-winged blackbird'
                'rocdov'='Rock dove'
                'shshaw'='Sharp-shinned hawk'
                'sonspa'='Song sparrow'
                'tuftit'='Tufted titmouse'
                'whbnut'='White-breasted nuthatch'
                'whtspa'='White-throated sparrow';

 value everseen 0=' '
                1='****';
run;

Arrange the observations by site ID.
proc sort data=feederbirds;
  by id;
run;

Use the labels of the report variables in the PROC PRINT report as column headings.
proc print data=feederbirds label;

List the observations in order by site ID.
  by id

Include in the BY statement the variables with values that are constant for each site ID. The values of these variables will be inserted in the titles. Since the site characteristic variables are constant for each site, it is not necessary to sort the data set by these variables. Indicate that these variables have not been sorted by preceding each variable with the NOTSORTED keyword.
     notsorted countsitesize
     notsorted countsitedesc
     notsorted density
     notsorted pop;

Identify observations by the values of the variable on the ID statement rather than the observation numbers.
  id species;

  title "Project FeederWatch Counts for Ten
 Observation
         Periods in Minnesota during 2002-2003";

Substitute the current values of the BY variables in the next three TITLE statements where enclosed by #BYVAL and parentheses.
  title2 "Counts for Site #byval(id)";
  title3 "Site Description: #byval(countsitesize) in
          #byval(countsitedesc)";
  title4 "Community: #byval(density) with a population
          of #byval(pop)";
  footnote1 "Key to Ten Observation Periods:";
  footnote2 ' 1: 09nov2002-22nov2002  '
            '2: 23nov2002-06dec2002  '
            '3: 07dec2002-20dec2002 '
            '4: 21dec2002-03jan2003';
  footnote3 ' 5: 04jan2003-17jan2003 '
            '6: 18jan2003-31jan2003  '
            '7: 01feb2003-14feb2003 '
            '8: 15feb2003-28feb2003';
  footnote4 ' 9: 01mar2003-14mar2003 '
            '10: 15mar2003-28mar2003';

List the variables whose values vary within each site.
  var everseen p1-p10;
  format countsitesize size. countsitedesc desc.
         density dens. pop pop.
         species $species. everseen everseen.;
  label species='Species'
        p1='P1'
        p2='P2'
        p3='P3'
        p4='P4'
        p5='P5'
        p6='P6'
        p7='P7'
        p8='P8'
        p9='P9'
        p10='P10'
        everseen='Ever Seen';

run;

Reset options to their default settings.
options byline center missing='.';


A Closer Look

Working with #BYVAL, #BYVAR, and #BYLINE when Customizing Titles

When your PROC steps include a BY statement, you can customize your titles by taking advantage of the #BYVAL, #BYVAR, and #BYLINE features. These three features insert text at the position you place them in your TITLE statements.

The BYLINE/NOBYLINE SAS option controls the automatic printing of BY lines. Submit

    options nobyline;

to turn off the BYLINE option before using the #BYVAL, #BYVAR, or #BYLINE features. As with other SAS options, NOBYLINE remains in effect until you reset it with

    options byline;

Table 2.3 describes the #BYVAL, #BYVAR, and #BYLINE features.

Table 2.3. #BYVAL, #BYVAR, and #BYLINE features
FeatureSpecificationAction
#BYVAL#BYVALnReplaces #BYVAL in the text string with the current value of the nth BY variable in the BY statement.
#BYVAL(variable-name)Replaces #BYVAL in the text string with the current value of the BY variable whose name is enclosed in parentheses.
#BYVAR#BYVARnReplaces #BYVAR in the text string with the name or label of the nth BY variable in the BY statement. Use the variable name only if the variable does not have a label.
#BYVAR(variable-name)Replaces #BYVAR in the text string with the name or label of the BY variable whose name is enclosed in parentheses in the BY statement. Use the variable name only if the variable does not have a label.
#BYLINE Replaces #BYLINE in the text string with the entire BY line.

When writing TITLE statements, terminate either of the two types of #BYVAL specifications and the two types of #BYVAR specifications with a delimiting character, such as a space or other nonalphanumeric character.

If you want the #BYVAL or #BYVAR substitution to be followed immediately by other text and not the delimiter, terminate the #BYVAL or #BYVAR specification with a trailing dot, just as you would with macro variables.

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.

The BYLINE/NOBYLINE SAS system options. See “SAS System Options” in SAS 9.1 Language Reference: Dictionary.

Inserting BY-group information in titles. See “Creating Titles that Contain BY-Group Information” in the “Fundamental Concepts for Using Base SAS Procedures” 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.

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

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