Usage Note 49534: When using #BYVAL in a TITLE statement with ODS RTF, only one title is written on each page when using the STARTPAGE and BODYTITLE options
When using #BYVAL in a TITLE statement with ODS RTF, only one title is written on each page when using the STARTPAGE and BODYTITLE options.
Two tables are displayed on page one of the RTF file but only one title when you are using code similar to the following. The code uses the STARTPAGE=NO and BODYTITLE options in the ODS RTF statement.
ods _all_ close;
ods rtf file="test.rtf" startpage=no
bodytitle nogtitle;
title1 h=12pt "GROUP: #byval(group)";
proc print data=one;
by group;
run;
ods rtf close;
ods listing;
There is no second title for the second table.
This issue occurs because the #BYVAL is resolved when a new page is generated rather than when the new table is written.
The sample code on the Full Code tab illustrates a circumvention for the problem. The code uses CALL EXECUTE in a DATA step to run the procedure multiple times, once for each unique value of the BY variable.
Operating System and Release Information
| SAS System | Base SAS | z/OS | 9.2 TS1M0 | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |
| Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |
| Microsoft® Windows® for x64 | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |
| Microsoft Windows XP Professional | 9.2 TS1M0 | |
| Windows Vista | 9.2 TS1M0 | |
| Windows Vista for x64 | 9.2 TS1M0 | |
| 64-bit Enabled AIX | 9.2 TS1M0 | |
| 64-bit Enabled HP-UX | 9.2 TS1M0 | |
| 64-bit Enabled Solaris | 9.2 TS1M0 | |
| HP-UX IPF | 9.2 TS1M0 | |
| Linux | 9.2 TS1M0 | |
| Linux for x64 | 9.2 TS1M0 | |
| OpenVMS on HP Integrity | 9.2 TS1M0 | |
| Solaris for x64 | 9.2 TS1M0 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
This code uses a CALL EXECUTE statement within DATA step code to call the PRINTIT macro multiple times, once for each unique value of the BY variable. With this technique, note that a WHERE statement is used in the PROC PRINT step instead of a BY statement.
/* Create test data */
data test;
do group=1 to 2;
do x=1 to 5;
y=ranuni(123);
output;
end;
end;
run;
/* Sort the data set by group */
proc sort data=test;
by group;
run;
/* Place the PROC PRINT code inside of a macro */
/* and use a WHERE statement instead of a BY */
/* statement. */
%macro printit(mgroup);
title1 h=12pt "GROUP: &mgroup";
proc print data=test;
where group=&mgroup;
run;
%mend;
ods _all_ close;
ods rtf file="test.rtf" startpage=no
bodytitle nogtitle;
/* Use CALL EXECUTE within DATA step code to */
/* call the PRINTIT macro once for each unique */
/* value of the BY variable. */
data _null_;
set test;
by group;
if first.group then call execute('%printit(' || trim(left(group)) || ')');
run;
ods rtf close;
ods listing;
When using #BYVAL in a TITLE statement with ODS RTF, only one title is written on each page when using the STARTPAGE and BODYTITLE options.
| Date Modified: | 2013-04-16 14:41:48 |
| Date Created: | 2013-03-28 10:34:46 |