BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
dmuenz
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Kathryn_SAS
SAS Employee

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;

View solution in original post

5 REPLIES 5
Ksharp
Super User

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 */
 
 

Ksharp_0-1760082974451.png

 

dmuenz
Obsidian | Level 7
Thanks, @Ksharp! Using PRETEXT= and POSTTEXT= works for tables with PROC REPORT, but is there a similar solution for figures with e,g, PROC SGPLOT?
Kathryn_SAS
SAS Employee

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;
dmuenz
Obsidian | Level 7
Thank you, @Kathryn_SAS! This works and completely solves my problem with minimal extra code or refactoring. But this does seem like a bug in ODS RTF. Do you know if it's been fixed in newer versions of SAS (I'm using SAS 9.4M6) or at least previously reported?
Kathryn_SAS
SAS Employee

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;

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1659 views
  • 6 likes
  • 3 in conversation