Apologies if this is a duplicate -- there are several closely related posts on this forum, but I did not see one with exactly my issue...
I'm using ODS RTF with the BODYTITLE option, and I want some pages to be portrait and others landscape. Oddly, I can start the output file in portrait and then change to landscape, but if I start in landscape then I cannot change to portrait.
Here's a minimal reproducible example, creating a macro that prints a two-page RTF file. You can specify the orientation of each page using the macro parameters.
%macro rtf(orient1, orient2);
options orientation=&orient1;
ods rtf file="Orientation - &orient1 to &orient2..rtf" bodytitle;
title "Page 1 Orientation: &orient1";
proc print data=sashelp.class(obs=1); run;
options orientation=&orient2;
ods rtf;
title "Page 2 Orientation: &orient2";
proc print data=sashelp.class(obs=1); run;
ods rtf close;
%mend;
%rtf(Portrait, Landscape) /* success: page 1 is portrait, page 2 is landscape */
%rtf(Landscape, Portrait) /* failure: both pages are landscape */
This odd behavior happens only when I use the BODYTITLE option. If I remove that option, then the page orientation always changes as expected. But I don't want my table/figure titles & footnotes in the document header & footer, so I prefer to use BODYTITLE.
I can also fix the problem by switching to ODS TAGSETS.RTF. That works, but I already have a large codebase creating tables & figures using ODS RTF, and if I switch one over to using TAGSETS.RTF then for formatting consistency I'd need to switch all of them. I'd prefer to avoid that extra work.
Any idea how to fix the above code? I tried playing around with the STARTPAGE option in the ODS RTF statements, but couldn't find anything that helped.
I'm using SAS 9.4M6 in SAS Studio.
The following is another work-around: Specify an orientation of portrait before the ODS RTF FILE= statement, and then toggle the output to landscape after the ODS RTF FILE= statement. The sample code below demonstrates this:
ods listing close;
options orientation=portrait;
ods rtf file="c:\temp\file.rtf" bodytitle;
options orientation=landscape;
ods rtf;
title 'Landscape';
proc print data=sashelp.class;
run;
options orientation=portrait;
ods rtf;
title 'Portrait';
proc print data=sashelp.shoes(obs=10);
run;
ods rtf close;
ods listing;
You can use option PRETEXT= to replace BODYTITLE and also could make change from landscape to portrait:
%macro rtf(orient1, orient2);
options orientation=&orient1;
ods rtf file="c:\temp\Orientation - &orient1 to &orient2..rtf" ;
proc report data=sashelp.class(obs=1) nowd
style(report)={pretext="Page 1 Orientation: &orient1" fontsize=8 fontweight=bold };
run;
options orientation=&orient2;
ods rtf;
proc report data=sashelp.class(obs=1) nowd
style(report)={pretext="Page 2 Orientation: &orient2" fontsize=8 fontweight=bold};
run;
ods rtf close;
%mend;
title;
/*%rtf(Portrait, Landscape) success: page 1 is portrait, page 2 is landscape */
%rtf(Landscape, Portrait) /* failure: both pages are landscape */
The following is another work-around: Specify an orientation of portrait before the ODS RTF FILE= statement, and then toggle the output to landscape after the ODS RTF FILE= statement. The sample code below demonstrates this:
ods listing close;
options orientation=portrait;
ods rtf file="c:\temp\file.rtf" bodytitle;
options orientation=landscape;
ods rtf;
title 'Landscape';
proc print data=sashelp.class;
run;
options orientation=portrait;
ods rtf;
title 'Portrait';
proc print data=sashelp.shoes(obs=10);
run;
ods rtf close;
ods listing;
This is an ongoing issue for the RTF destination. Other than the work-around I provided, the other alternative is to use the Tagsets.RTF destination.
ods listing close;
options orientation=landscape;
ods tagsets.rtf file='test.rtf';
title 'Landscape';
proc print data=sashelp.class;
run;
options orientation=portrait;
title 'Portrait';
proc print data=sashelp.shoes(obs=10);
run;
ods tagsets.rtf close;
ods listing;
title;
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.