PRINT Procedure

Example 7: Controlling the Layout of a Report with Many Variables

Features:

PROC PRINT statement options: : ROWS=

ID statement options: : STYLE

Other features:

ODS RTF statement

SAS data set options: : OBS=

Data set: EMPDATA

Details

This example shows two ways of printing a data set with a large number of variables: one is the default, printing multiple rows when there are a large number of variables, and the other uses ROWS= option to print one row. The ROWS= option is valid only for the Listing destination. For detailed explanations of the layouts of these two reports, see the option ROWS= and Page Layout .
These reports use a page size of 24 and a line size of 64 to help illustrate the different layouts.

Program: Creating a Listing Report

data empdata;
   input IdNumber $ 1-4 LastName $ 9-19 FirstName $ 20-29
         City $ 30-42 State $ 43-44 /
         Gender $ 1 JobCode $ 9-11 Salary 20-29 @30 Birth date9.
         @43 Hired date9. HomePhone $ 54-65;
   format birth hired date9.;
   datalines;
1919    Adams      Gerald    Stamford     CT
M       TA2        34376     15SEP1970      07JUN2005    203/781-1255
1653    Alexander  Susan     Bridgeport   CT
F       ME2        35108     18OCT1972      12AUG1998    203/675-7715

. . . more lines of data . . .

1407    Grant      Daniel    Mt. Vernon   NY
M       PT1        68096     26MAR1977      21MAR1998    914/468-1616
1114    Green      Janice    New York     NY
F       TA2        32928     21SEP1977      30JUN2006    212/588-1092
;
proc print data=empdata(obs=12);
   id idnumber;
   title 'Personnel Data';
run;
proc print data=empdata(obs=12) rows=page;
   id idnumber;
   title 'Personnel Data';
run;

Program Description

Create the EMPDATA data set. The data set EMPDATA contains personal and job-related information about a company's employees. The DATA step creates this data set.
data empdata;
   input IdNumber $ 1-4 LastName $ 9-19 FirstName $ 20-29
         City $ 30-42 State $ 43-44 /
         Gender $ 1 JobCode $ 9-11 Salary 20-29 @30 Birth date9.
         @43 Hired date9. HomePhone $ 54-65;
   format birth hired date9.;
   datalines;
1919    Adams      Gerald    Stamford     CT
M       TA2        34376     15SEP1970      07JUN2005    203/781-1255
1653    Alexander  Susan     Bridgeport   CT
F       ME2        35108     18OCT1972      12AUG1998    203/675-7715

. . . more lines of data . . .

1407    Grant      Daniel    Mt. Vernon   NY
M       PT1        68096     26MAR1977      21MAR1998    914/468-1616
1114    Green      Janice    New York     NY
F       TA2        32928     21SEP1977      30JUN2006    212/588-1092
;
Print only the first 12 observations in a data set. The OBS= data set option uses only the first 12 observations to create the report. (This is just to conserve space here.) The ID statement identifies observations with the formatted value of IdNumber rather than with the observation number. This report is shown in Output: Listing.
proc print data=empdata(obs=12);
   id idnumber;
   title 'Personnel Data';
run;
Print a report that contains only one row of variables on each page. ROWS=PAGE prints only one row of variables for each observation on a page. This report is shown in Layout Produced by the ROWS=PAGE Option: Listing Output.
proc print data=empdata(obs=12) rows=page;
   id idnumber;
   title 'Personnel Data';
run;

Output: Listing

In the traditional procedure output, each page of this report contains values for all variables in each observation. In the HTML output, this report is identical to the report that uses ROWS=PAGE.
Note that PROC PRINT automatically splits the variable names that are used as column headings at a change in capitalization if the entire name does not fit in the column. Compare the column headings for LastName (which fits in the column) and FirstName (which does not fit in the column).
Default Layout for a Report with Many Variables: Listing Output
                Personnel Data                        1

  Id                   First
Number    LastName     Name           City       State    Gender

 1919     Adams        Gerald      Stamford       CT        M
 1653     Alexander    Susan       Bridgeport     CT        F
 1400     Apple        Troy        New York       NY        M
 1350     Arthur       Barbara     New York       NY        F
 1401     Avery        Jerry       Paterson       NJ        M
 1499     Barefoot     Joseph      Princeton      NJ        M
 1101     Baucom       Walter      New York       NY        M

  Id      Job
Number    Code    Salary      Birth      Hired     HomePhone

 1919     TA2      34376    15SEP70    07JUN05    203/781-1255
 1653     ME2      35108    18OCT72    12AUG98    203/675-7715
 1400     ME1      29769    08NOV85    19OCT06    212/586-0808
 1350     FA3      32886    03SEP63    01AUG00    718/383-1549
 1401     TA3      38822    16DEC68    20NOV93    201/732-8787
 1499     ME3      43025    29APR62    10JUN95    201/812-5665
 1101     SCP      18723    09JUN80    04OCT98    212/586-8060
                Personnel Data                        2

  Id                   First
Number    LastName     Name           City       State    Gender

 1333     Blair        Justin      Stamford       CT        M
 1402     Blalock      Ralph       New York       NY        M
 1479     Bostic       Marie       New York       NY        F
 1403     Bowden       Earl        Bridgeport     CT        M
 1739     Boyce        Jonathan    New York       NY        M

  Id      Job
Number    Code    Salary      Birth      Hired     HomePhone

 1333     PT2      88606    02APR79    13FEB03    203/781-1777
 1402     TA2      32615    20JAN71    05DEC98    718/384-2849
 1479     TA3      38785    25DEC66    08OCT03    718/384-8816
 1403     ME1      28072    31JAN79    24DEC99    203/675-3434
 1739     PT1      66517    28DEC82    30JAN00    212/587-1247

Each page of this report contains values for only some of the variables in each observation. However, each page contains values for more observations than the default report does.
Layout Produced by the ROWS=PAGE Option: Listing Output
                         Personnel Data                        3

  Id                   First
Number    LastName     Name           City       State    Gender

 1919     Adams        Gerald      Stamford       CT        M
 1653     Alexander    Susan       Bridgeport     CT        F
 1400     Apple        Troy        New York       NY        M
 1350     Arthur       Barbara     New York       NY        F
 1401     Avery        Jerry       Paterson       NJ        M
 1499     Barefoot     Joseph      Princeton      NJ        M
 1101     Baucom       Walter      New York       NY        M
 1333     Blair        Justin      Stamford       CT        M
 1402     Blalock      Ralph       New York       NY        M
 1479     Bostic       Marie       New York       NY        F
 1403     Bowden       Earl        Bridgeport     CT        M
 1739     Boyce        Jonathan    New York       NY        M
                        Personnel Data                        4

  Id      Job
Number    Code    Salary      Birth      Hired     HomePhone

 1919     TA2      34376    15SEP70    07JUN05    203/781-1255
 1653     ME2      35108    18OCT72    12AUG98    203/675-7715
 1400     ME1      29769    08NOV85    19OCT06    212/586-0808
 1350     FA3      32886    03SEP63    01AUG00    718/383-1549
 1401     TA3      38822    16DEC68    20NOV93    201/732-8787
 1499     ME3      43025    29APR62    10JUN95    201/812-5665
 1101     SCP      18723    09JUN80    04OCT98    212/586-8060
 1333     PT2      88606    02APR79    13FEB03    203/781-1777
 1402     TA2      32615    20JAN71    05DEC98    718/384-2849
 1479     TA3      38785    25DEC66    08OCT03    718/384-8816
 1403     ME1      28072    31JAN79    24DEC99    203/675-3434
 1739     PT1      66517    28DEC82    30JAN00    212/587-1247

Program: Creating an RTF Report

options nodate pageno=1 linesize=64 pagesize=24;
ods rtf file='your_file.rtf';
proc print data=empdata(obs=12);
   id idnumber;
   title 'Personnel Data';
run;
ods rtf close;

Program Description

The RTF output shows all data in one row. The ROWS= option is valid only for the Listing destination.
options nodate pageno=1 linesize=64 pagesize=24;
Create output for Microsoft Word and specify the file to store the output in. The ODS RTF statement opens the RTF destination and creates output formatted for Microsoft Word. The FILE= argument specifies the external file that contains the RTF output.
ods rtf file='your_file.rtf';
proc print data=empdata(obs=12);
   id idnumber;
   title 'Personnel Data';
run;
Close the RTF destination. The ODS RTF CLOSE statement closes the RTF destination.
ods rtf close;

Output: RTF

Layout for a Report with Many Variables: RTF Output
Layout for a Report with Many Variables: RTF Output