Customize the appearance of the report produced in the related technique of Example 2.4. Use “traffic lighting” to draw attention to specific results in the report by setting style elements to specific colors. Send the output to a nonlisting destination.
Data Set | POWERUSE |
Report Example | Related Technique in Example 2.4 |
Featured Steps | PROC FORMAT PROC PRINT |
Featured Step Statements and Options | PROC FORMAT
ODS STYLE= options placed on these PROC PRINT statements:
|
Output Destination of Example | HTML |
A Closer Look | Placing STYLE= Options in a PROC PRINT Step |
Other Examples That Use This Data Set | Examples 2.4, 2.5, and 2.6 |
PROC PRINT produced the report in the Related Technique of Example 2.4. It listed the power usage by type, service, and month for the first two quarters of a year and summed power usage by type and overall.
This example sends a PROC PRINT report to a nonlisting destination. It illustrates how to assign attributes to style elements in several locations of the report. Additionally, it sets the background color of the cells of the SERVICE variable based on the values of the variable. It does this by defining a format that associates colors to values. Within the PROC PRINT step, the background attribute of the variable is set to the format name. Formatting in this manner presents a visual way to group similar values of a variable.
Define formats for TYPE and SERVICE as in Example 2.4. | proc format; value $type 'res'='Residential' 'com'='Commercial'; value $service 'gen'='General Service' 'wtr'='Water Heating' 'op' ='Off Peak' 'spc'='Space Heating' 'fld'='Flood Lights' 'area'='Area Lights' 'oth'='Other Service'; |
Define a format to group the formatted values of SERVICE to colors. | value $colorserv 'Area Lights', 'Flood Lights'='grayee' 'General Service', Other Service'='graydd' 'Off Peak'='graycc' 'Space Heating', Water Heating'='graybb'; run; |
Do not send results to the LISTING destination. | ods listing close; |
Send subsequent results to the HTML destination and save the results in a file. | ods html file='c: eportsexample23.html'; title 'Regional Energy'; title2 'Quarterly Use by Residential and Commercial Customers'; proc sort data=poweruse out=sorted; by type service; run; |
Assign style attributes to several locations in the report. | proc print data=sorted label |
Set the background color of the data cells. | style(data)={background=white} |
Apply style changes to the column headings. Set the background color and the font. | style(header)={background=white font_face='Times'} |
Set the background color of the OBS column (In this example, that’s the same as the ID column). | style(obs)={background=white} |
Set the background color of the heading for the OBS column. | style(obsheader)={background=white} |
Apply style changes to the SUM line. Set the background color of the rows and specify the font. Italicize the text. | style(total)= {background=white font_face='Times' font_style=italic} |
Apply style changes to the structural part of the PROC PRINT table. Set the color between the lines outlining the cells. Set the color of the borders of the table. | style(table)={background=black bordercolor=black}; |
Apply style changes to the ID column, which in this example is the same as the OBS column. Set the font and italicize the text. | id type / style={font_face='Times' font_style=italic}; by type; |
Apply style changes to the SERVICE column. Set the background color of the cells according to the formatted values of SERVICE. Italicize the text, write the text in bold, and set the font. | var service / style={background=$colorserv. font_style=italic font_weight=bold font_face='Times'}; var jan feb mar apr may jun; sum jan feb mar apr may jun; label type='00'x service='Service' jan='January' feb='February' mar='March' apr='April' may='May' jun='June'; |
Format the variables as in Example 2.4. | format type $type. service $service. jan--jun comma6.; run; |
Terminate sending output to the HTML destination. | ods html close; |
Send subsequent output to the LISTING destination. | ods listing; |
A Closer Look |
When you send your PROC PRINT report to a nonlisting destination, you can take advantage of the formatting capabilities of the destination by customizing style elements in the report. You can do this either by using the STYLE= option in PROC PRINT or by defining a style and referencing it on the ODS destination statement.
Modifying style attributes in a PROC PRINT step makes changes only to the report in which the modifications are applied. If you want to modify the output the same way repeatedly, you might find it more efficient to define and save a style rather than to code the same style attributes every time you execute a report. Examples 6.12, 6.14 and 6.15 define styles and table definitions for that purpose.
The remainder of this section discusses how to use the STYLE= option in PROC PRINT. The syntax of the STYLE= option is
STYLE<(location(s))>=<style-element-name> <[style-attribute-specification(s)]
You can add the STYLE= option to the following PROC PRINT statements:
□ | PROC PRINT |
□ | ID |
□ | SUM |
□ | VAR |
A PROC PRINT report can be divided into components whose style attributes can be modified. You can add options to the PROC PRINT statement to modify style attributes in several report locations, as listed in Table 6.10.
The PROC PRINT, ID, SUM, and VAR statements each have default locations. For the PROC PRINT, ID, and VAR statements, the default locations are DATA and HEADER. For the SUM statement, the default locations are DATA, HEADER, and TOTAL.
For example, if you omit the location on a STYLE= option placed on a VAR statement and specify an attribute for the style element “font_style,” both the data cells and headings for the variables on the VAR statement are modified according to the attribute assigned to “font_style.”
The preceding example sets attributes for style elements on the PROC PRINT statement for the following report locations: DATA, HEADER, OBS, OBSHEADER, TABLE, and TOTAL. It also sets attributes on the ID and VAR statements. The ID TYPE statement causes TYPE to become the OBS column. Therefore, you can assign attributes for TYPE either in the ID statement or on the PROC PRINT statement STYLE= options for the locations OBS and OBSHEADER.
18.225.55.151