The SAS Output Delivery System and reporting techniques

ODS RTF Output with by-Variable

Reply
Contributor
Posts: 44

ODS RTF Output with by-Variable

Hello,

I have two proc-steps within an ODS RTF. In my Procs i generate Graphics per patient and per time-period (1 to 5). Is it possible to sort the Graphics from both proc-Steps per patient in my RTF-Output? So that i have have first all Graphs from patient a, then patient b, patient c.... ? I have always different numbers of observations and my patient-IDs are not chronological.

Here is my code, I use SAS 9.2 Phase 1:

goptions reset=all border;
options nobyline;
title1 font='Arial/bold' height=10pt Ls=1 #byline;

ODS rtf;
ODS RTF Startpage=OFF;
ODS GRAPHICS ON ;

PROC GPLOT Data=VersuchGrafiken;
symbol v=plus ci=black i=join;
symbol2 v=plus ci=green i=join;
symbol3 v=plus ci=red i=join;
symbol4 v=plus ci=blue i=join;
symbol5 v=plus ci=grey i=join;
axis1 LABEL=(angle=90 'TNSS') Order=(0 1 2 3 4 5 6 7 8 9 10 11 12) minor=none;
axis2 LABEL=('Time [min]') Order=(-60 to 360 by 60)offset=(,2);
PLOT answer_num*time_value=period_name /overlay vaxis=axis1 haxis=axis2 hminor=2 vref=6 LVREF=20 ;
where time_value NE .;
By random_no;
*Title '#byline';
LABEL random_no='Randomno' period_name='Periode';
RUN;

PROC GPLOT Data=VersuchGrafiken;
symbol v=plus ci=black i=join;
axis1 LABEL=(angle=90 'TNSS') Order=(0 1 2 3 4 5 6 7 8 9 10 11 12) minor=none;
axis2 LABEL=('Time [min]') Order=(-60 to 360 by 60);
PLOT answer_num*time_value /vaxis=axis1 haxis=axis2 hminor=2 vref=6 LVREF=20;
where time_value NE .;
By period_name random_no ;
*Title '#byline';
LABEL random_no='Randomno' period_name='Periode';
RUN;
ODS GRAPHICS OFF;
ODS rtf CLOSE;



Thanks for your help!

Marie
SAS Super FREQ
Posts: 8,866

Re: ODS RTF Output with by-Variable

Hi:
Your issue is caused by the fact that the first procedure needs to finish ALL the BY groups before the second procedure can start. The type of "rearranging" that you are discussing -- so that all the reports/graphs for Patient A are together and then all the reports/graphs for Patient B are together is typically handled in one of two ways:

1) Use macro processing or a macro program to create multiple graphs. And, optionally, would you still want 1 RTF output file for all Patients or would you want 1 RTF output file for each Patient??? Either way, essentially, you would replace the BY group processing with a Macro program that would iterate through a list of patients so that both graphs were produced for Patient A and then both graphs for Patient B and then on and one until all the graphs were produced -- one set for each patient.

Conceptually, the general idea would be something like this:
[pre]
** define the macro program;
%macro grafpat(patient=);
...SAS/Graph code and other statements, like GOPTIONS, etc;
... please note that the ODS GRAPHICS ON statement is not needed or used for;
... standard PROC GPLOT procedures;
%mend grafpat;

** create a single RTF file by running the macro program one time for each patient;
** a more advanced macro program would automatically generate the macro calls;
** for each patient based on a list of patients from the data.;
** This example just shows the simplest method of manually coding the macro;
** program invocation.;
ods rtf file='allpts.rtf' startpage=no;

%grafpat(patient=A)
%grafpat(patient=B)
%grafpat(patient=C)

ods rtf close;
[/pre]

For a general introduction to the SAS Macro Facility, this is a good paper:
http://www2.sas.com/proceedings/sugi28/056-28.pdf
For more advanced examples of Macro processing, these are good papers:
http://www.ats.ucla.edu/stat/sas/library/nesug99/bt046.pdf
http://www2.sas.com/proceedings/sugi30/028-30.pdf
http://www2.sas.com/proceedings/sugi30/130-30.pdf

2) Create your graphs as you do now, but store them in an ODS DOCUMENT store and then rearrange the graphical output objects to be in the structure you want using PROC DOCUMENT commands. Then replay the newly rearranged DOCUMENT store to your destination of interest.

You will probably find more information on the first, macro approach, because that has been around for a while. The second approach is a newer approach and you would have to research the ODS DOCUMENT/PROC DOCUMENT capability (and at least have SAS 9 in order to use this feature of SAS). For more information about ODS DOCUMENT, refer to the documentation and this user-group paper:
http://support.sas.com/resources/papers/sgf09/318-2009.pdf

Also note that the ODS GRAPHICS statement is designed for template-based SAS/GRAPH procedures, such as SGPLOT, SGPANEL and SGSCATTER and the automatic graphs produced by SAS/STAT procedures. The use of ODS GRAPHICS ON is irrelevant in the context of "classic" device based SAS/GRAPH procedures such as PROC GPLOT.

cynthia
Contributor
Posts: 44

Re: ODS RTF Output with by-Variable

Posted in reply to Cynthia_sas
thank you for your help!
Ask a Question
Discussion stats
  • 2 replies
  • 180 views
  • 0 likes
  • 2 in conversation