PRINT Procedure

Example 8: Creating a Customized Layout with BY Groups and ID Variables

Features:
Procedure features::
BY statement
ID statement
SUM statement
VAR statement
Other features:

SORT procedure

Data set: EMPDATA

Details

This customized report demonstrates the following tasks:
  • selects variables to include in the report and the order in which they appear
  • selects observations to include in the report
  • groups the selected observations by JobCode
  • sums the salaries for each job code and for all job codes
  • displays numeric data with commas and dollar signs

Program: Creating a Listing Report

options nodate pageno=1 linesize=64 pagesize=60;
proc sort data=empdata out=tempemp;
   by jobcode gender;
run;
proc print data=tempemp split='*';
   id jobcode;
   by jobcode;
   var gender salary;
   sum salary;
   label jobcode='Job Code*========'
         gender='Gender*======'
         salary='Annual Salary*=============';
   format salary dollar11.2;
   where jobcode contains 'FA' or jobcode contains 'ME';
   title 'Salay Expenses';
run;

Program Description

Create and sort a temporary data set. PROC SORT creates a temporary data set in which the observations are sorted by JobCode and Gender.
options nodate pageno=1 linesize=64 pagesize=60;
proc sort data=empdata out=tempemp;
   by jobcode gender;
run;
Identify the character that starts a new line in column headings.SPLIT= identifies the asterisk as the character that starts a new line in column headings.
proc print data=tempemp split='*';
Specify the variables to include in the report. The VAR statement and the ID statement together select the variables to include in the report. The ID statement and the BY statement produce the special format.
   id jobcode;
   by jobcode;
   var gender salary;
Calculate the total value for each BY group. The SUM statement totals the values of Salary for each BY group and for the whole report.
   sum salary;
Assign labels to the appropriate variables. The LABEL statement associates a label with each variable for the duration of the PROC PRINT step. When you use SPLIT= in the PROC PRINT statement, the procedure uses labels for column headings.
   label jobcode='Job Code*========'
         gender='Gender*======'
         salary='Annual Salary*=============';
Create formatted columns. The FORMAT statement assigns a format to Salary for this report. The WHERE statement selects for the report only the observations for job codes that contain the letters 'FA' or 'ME'. The TITLE statements specify two titles.
   format salary dollar11.2;
   where jobcode contains 'FA' or jobcode contains 'ME';
   title 'Salay Expenses';
run;

Output: Listing

The ID and BY statements work together to produce this layout. The ID variable is listed only once for each BY group. The BY lines are suppressed. Instead, the value of the ID variable, JobCode, identifies each BY group.
Creating a Customized Layout with BY Groups and ID Variables: Listing Output
                        Salay Expenses                        1

              Job Code    Gender    Annual Salary
              ========    ======    =============

                FA1         F         $23,177.00
                            F         $22,454.00
                            M         $22,268.00
              --------              -------------
                FA1                   $67,899.00

                FA2         F         $28,888.00
                            F         $27,787.00
                            M         $28,572.00
              --------              -------------
                FA2                   $85,247.00

                FA3         F         $32,886.00
                            F         $33,419.00
                            M         $32,217.00
              --------              -------------
                FA3                   $98,522.00

                ME1         M         $29,769.00
                            M         $28,072.00
                            M         $28,619.00
              --------              -------------
                ME1                   $86,460.00

                ME2         F         $35,108.00
                            F         $34,929.00
                            M         $35,345.00
                            M         $36,925.00
                            M         $35,090.00
                            M         $35,185.00
              --------              -------------
                ME2                  $212,582.00

                ME3         M         $43,025.00
                                    =============
                                     $593,735.00

Program: Creating an HTML Report

options nodate pageno=1 linesize=64 pagesize=60 obs=15;
proc sort data=empdata out=tempemp;
   by jobcode gender;
run;
ods html file='your_file.html';
proc print data=tempemp (obs=10) split='*';
 id jobcode;
   by jobcode;
   var gender salary;
   sum salary;
   label jobcode='Job Code*========'
         gender='Gender*======'
         salary='Annual Salary*=============';
   format salary dollar11.2;
   where jobcode contains 'FA' or jobcode contains 'ME';
   title 'Salary Expenses';
run;

Program Description

options nodate pageno=1 linesize=64 pagesize=60 obs=15;
proc sort data=empdata out=tempemp;
   by jobcode gender;
run;
Produce HTML output and specify the file to store the output in.The HTML destination is the default ODS destination. The ODS HTML statement FILE= option specifies the external file that contains the HTML output.
ods html file='your_file.html';
proc print data=tempemp (obs=10) split='*';
 id jobcode;
   by jobcode;
   var gender salary;
   sum salary;
   label jobcode='Job Code*========'
         gender='Gender*======'
         salary='Annual Salary*=============';
   format salary dollar11.2;
   where jobcode contains 'FA' or jobcode contains 'ME';
   title 'Salary Expenses';
run;

Output: HTML

Creating a Customized Layout with BY Groups and ID Variables: Default HTML Output
Creating a Customized Layout with BY Groups and ID Variables: Default HTML Output

Program: Creating an HTML Report with the STYLE Option

options nodate pageno=1 linesize=64 pagesize=60 obs=15;
proc sort data=empdata out=tempemp;
   by jobcode gender;
run;
ods html file='your_file.html';
proc print data=tempemp (obs=10) split='*' style(HEADER)
=
                                  {fontstyle=italic}
                                  style(DATA) =
                                  {backgroundcolor=blue foreground =
white};
 id jobcode;
   by jobcode;
   var gender salary;
   sum salary  / style(total)= {color=red};
   label jobcode='Job Code*========'
         gender='Gender*======'
         salary='Annual Salary*=============';
   format salary dollar11.2;
   where jobcode contains 'FA' or jobcode contains 'ME';
   title 'Expenses Incurred for';
   title2 'Salaries for Flight Attendants and Mechanics';
run;

Program Description

options nodate pageno=1 linesize=64 pagesize=60 obs=15;
proc sort data=empdata out=tempemp;
   by jobcode gender;
run;
ods html file='your_file.html';
Create stylized HTML output. The first STYLE option specifies that the font of the headers be changed to italic. The second STYLE option specifies that the background of cells that contain input data be changed to blue and the foreground of these cells be changed to white.
proc print data=tempemp (obs=10) split='*' style(HEADER)
=
                                  {fontstyle=italic}
                                  style(DATA) =
                                  {backgroundcolor=blue foreground =
white};
 id jobcode;
   by jobcode;
   var gender salary;
Create total values that are written in red. The STYLE option specifies that the color of the foreground of the cell that contain the totals be changed to red.
   sum salary  / style(total)= {color=red};
   label jobcode='Job Code*========'
         gender='Gender*======'
         salary='Annual Salary*=============';
   format salary dollar11.2;
   where jobcode contains 'FA' or jobcode contains 'ME';
   title 'Expenses Incurred for';
   title2 'Salaries for Flight Attendants and Mechanics';
run;

Output: HTML with Styles

Creating a Customized Layout with BY Groups and ID Variables: HTML Output Using Styles
Creating a Customized Layout with BY Groups and ID Variables: HTML Output Using Styles