Using STYLE/MERGE and STYLE/REPLACE in PROC REPORT

May 5, 2020
By

This post was kindly contributed by SAS Users - go there to comment and to read the full post.

When you route REPORT procedure output to any of the ODS destinations, you might want to apply style attributes to a column based on multiple variable values. To do that, you need to use CALL DEFINE statements in a COMPUTE block. This structure could then require complex logic and many CALL DEFINE statements to ensure that all combinations of the variable values and styles are applied appropriately. However, the STYLE/MERGE and STYLE/REPLACE attributes in the CALL DEFINE statement can simplify this process. They are useful when you have two or more COMPUTE blocks with CALL DEFINE statements and the CALL DEFINE statements refer to the same cell in a table.

Using the STYLE/MERGE attribute

The STYLE/MERGE attribute combines any new styles that are specified by the STYLE= argument with any existing styles that are already applied to values in the row or column. In this example, style attributes are applied to the Sex column. In the first COMPUTE block, if the value of Sex is F, the background color of the cell is yellow. In the second COMPUTE block for Age, if the value of Age is greater than 14, the color of the text in the Sex column is red. When STYLE/MERGE is used, that means that a yellow background that also has red text is used for any cell in the Sex column where the value is F and the corresponding Age is also greater than 14.

 
proc report data=sashelp.class; 
column sex age height weight;
define sex--weight / display;
 
compute sex;
if sex = 'F' then
 call define('sex', "style", "style=[background=yellow]"); 
endcomp;
 
compute age;
if age > 14 then
 call define('sex', "style/merge", "style=[color=red]"); 
endcomp;
run;

Here is the resulting output:

Using the STYLE/REPLACE attribute

The STYLE/REPLACE attribute replaces any existing styles for a row or column with the new styles that are specified by the STYLE= argument. In this example, style attributes are applied to the Sex column again. In the first COMPUTE block, if the value of Sex is F, the background color of the cell is yellow. In the second COMPUTE block for Age, if the value of Age is greater than 14, the color of the text in the Sex column is red. When STYLE/REPLACE is used, that means that red text only, without any background color, is used for any cell in the Sex column where the value is F and the corresponding Age is also greater than 14. The red-text style replaces the yellow background.

 
proc report data=sashelp.class; 
column sex age height weight;
define sex--weight / display;
 
compute sex;
if sex = 'F' then
 call define('sex', "style", "style=[background=yellow]"); 
endcomp;
 
compute age;
if age > 14 then	
 call define('sex', "style/replace", "style=[color=red]"); 
endcomp;
run;

Here is the resulting output:

The STYLE/MERGE and STYLE/REPLACE attributes are supported only in the CALL DEFINE statement in a COMPUTE block in PROC REPORT. These useful tools can simplify complex code and enable you to customize your PROC REPORT output with meaningful style choices.

Additional References

PROC REPORT: CALL DEFINE

Sample Note 43758: How to merge styles from multiple CALL DEFINE statements with PROC REPORT

Using STYLE/MERGE and STYLE/REPLACE in PROC REPORT was published on SAS Users.

This post was kindly contributed by SAS Users - go there to comment and to read the full post.

Tags: ,

Welcome!

SAS-X.com offers news and tutorials about the various SAS® software packages, contributed by bloggers. You are welcome to subscribe to e-mail updates, or add your SAS-blog to the site.

Sponsors







Dear readers, proc-x is looking for sponsors who would be willing to support the site in exchange for banner ads in the right sidebar of the site. If you are interested, please e-mail me at: tal.galili@gmail.com
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.