The SAS Output Delivery System and reporting techniques

How to combine different RTF file which have different Orientation by using ODS/PROC Document

Reply
Occasional Contributor
Posts: 6

How to combine different RTF file which have different Orientation by using ODS/PROC Document

Hi ,

I have created one RTF file with Portrait orientation and second rtf file with landscape orientation. i have used ODS document to create object for both file and then i wiil call both file by REPLAYin proc document to combine both file into one RTF file.

actually i can do this by using ODS RTF; ..as like below example.

***************************************************************************************

data a;

infile datalines;

input name : $20. exp : $20. num ;

datalines;

A same 40

A same 80

A same 90

A same 86

A other 420

A other 300

;

run;

data b;

infile datalines;

input name : $20. exp : $20. num ;

datalines;

D other 200

D other 125

D other 230

D other 250

;

run;

options orientation = portrait;

ods rtf file="outputpath\new.rtf" contents=on toc_data;

proc report data=a nowd contents="first table";

   column name exp num ;

   define name / display;

   define exp / display;

   define num / display;

run;

options orientation = landscape;

ods rtf;

proc report data=b nowd contents="second table";

   column name exp num ;

   define name / display;

   define exp / display;

   define num / display;

run;

ods rtf close;

****************************************************************************************************************************************

if i will follow above process then i need to write proc report every time to start new RTF page by ODS RTF statement (cause there are many seperate files will be created and then i need to combine into one file. so every time i can not write PROC REPORT).

but suppose i have below dataset.

data test;

infile datalines;

input name : $20. exp : $20. num ;

datalines;

A same 225

A same 350

A same 40

A same 80

D other 230

D other 250

D other 45

D other 73

;

run;

**********************************************

now from this dataset ,i will create two report on the base of name variable by using macro.one report will have PORTRAIT and Other will have LANDSCAPE orientation. macro will contain ODS DOCUMENT statement which store the Object of the report.

so i am not getting how can i combine this two rtf file with different orientation by REPLAY in PROC DOCUMENT.

or is there any alternative method to sort out this issue?

hope my concern will be clear to you...if not then plz let me know....

many thanks...

SAS Super FREQ
Posts: 8,814

Re: How to combine different RTF file which have different Orientation by using ODS/PROC Document

Hi:

  It is not entirely clear what you mean. ODS DOCUMENT is NOT storing your RTF file. It is storing the OUTPUT OBJECT from your procedure in a "frozen" state imagine that this is what is happening:

1) PROC REPORT runs ----> 2) object goes to ODS DOCUMENT and "freezes" before the destination ---> 3) PROC DOCUMENT REPLAY grabs the object and sends to your destination of choice

So in this scenario, #1 and #2 can happen on Monday, but #3 can happen on Wednesday. Then with PROC DOCUMENT REPLAY, you can send the objects to ANY ODS destination. Or you can send object from different document stores to the same output. Or you can rearrange objects. But you are NOT storing the "original" ODS RTF output. You are storing a copy of the output object that made the ODS RTF document.

  For example, in the code below, I am making 2 RTF files and also storing the output objects into a document store:

c:\temp\doc1_make_doc.rtf (2 reports) and c:\temp\doc2_make_doc.rtf (2 reports) -- let's say that I make those 2 RTF files on Friday. And, I also "freeze" the output objects in 1 document store. Then, on Monday, I want to replay the objects all together into 1 RTF file and also in an HTML file. I am not replaying the RTF "file" -- I am replaying the output objects. Normally with ODS DOCUMENT and PROC DOCUMENT if I do a simple REPLAY, then I replay the WHOLE document. But I need to change orientation in the new file. So that means I have to specify which object I want to replay, explicitly -- AND -- I have to switch orientation between objects for the REPLAY. That means I need to know the name of each object that I put in the DOCUMENT store. PROC DOCUMENT will give that information to me. Now, reassembling the output objects together into a NEW report is easy. Please see the screen shot of what the output object names look like in the document store. You should be able to run the attached code, it uses all SASHELP datasets.

  I recommend taking a look at the ODS DOCUMENT/PROC DOCUMENT examples. There are several good user group papers (here's mine http://support.sas.com/resources/papers/sgf09/318-2009.pdf) on the subject and even a book in the SAS Bookstore about ODS DOCUMENT.

Cynthia

ods document name=work.newreport(write);
options orientation=portrait;
** make the original RTF file and store a copy of the output objects in a document store;
ods rtf file='c:\temp\doc1_make_doc.rtf';
proc report data=sashelp.class nowd;
title "1) SASHELP.CLASS";
run;
 
options orientation=landscape;
ods rtf;
run;
   
proc report data=sashelp.cars(obs=20) nowd;
title "2) SASHELP.CARS";
run;
 
ods rtf close;
  

** make the second RTF file and store a copy of the output objects in the same document store;
** could be a different document store, it was easier for this example to make it the same;
options orientation=portrait;
ods rtf file='c:\temp\doc2_make_doc.rtf';
proc report data=sashelp.classfit nowd;
title "3) SASHELP.CLASSFIT";
format predict lower lowermean upper uppermean 7.2;
run;
 
options orientation=landscape;
ods rtf;
run;
   
proc report data=sashelp.Heart(obs=20) nowd;
where cholesterol gt .;
column status sex height weight ageatstart diastolic systolic mrw
       smoking chol_status bp_status weight_status smoking_status;
title "4)SASHELP.HEART";
run;
 
ods rtf close;
ods document close;  /* <--- close document store */
  

** get the names of the output objects;
ods listing;
proc document name=work.newreport;
  list / levels=all;
run;
quit;
ods listing close;
   
** now replay the ALL the separate output objects into 1 RTF file;
** and also make an HTML file as well;
** and switch orientation between objects -- will work for RTF, but orientation is irrelevant to HTML;
ods _all_ close;
  
options orientation=portrait;
ods rtf file='c:\temp\playback.rtf';
ods html file='c:\temp\playback.html';
    
proc document name=work.newreport;
  replay \Report#1\Report#1\Report#1;
run;
quit;
    
options orientation=landscape;
ods rtf; run;
proc document name=work.newreport;
  replay \Report#2\Report#1\Report#1;
run;
quit;
      
  
options orientation=portrait;
ods rtf; run;
proc document name=work.newreport;
  replay \Report#3\Report#1\Report#1;
run;
quit;
    
options orientation=landscape;
ods rtf; run;
proc document name=work.newreport;
  replay \Report#4\Report#1\Report#1;
run;
quit;
  
ods _all_ close;


ods_document_list_of_objects.png
Occasional Contributor
Posts: 6

Re: How to combine different RTF file which have different Orientation by using ODS/PROC Document

i got it..i need to write one replay statement for report and one for graph seperately as per my requirement .

thank you so much cynthia for your kind help...

Ask a Question
Discussion stats
  • 2 replies
  • 824 views
  • 0 likes
  • 2 in conversation