The SAS Output Delivery System and reporting techniques

Using ODS for a multi-page GPLOT

Reply
N/A
Posts: 0

Using ODS for a multi-page GPLOT

I am trying to use ODS to create a multi-page PDF document of a GPLOT. My dataset includes two variables, NUM and RATE. The dataset is sorted by PAGE and I want a new GPLOT page for each value of PAGE, but I'm getting the same GPLOT for each value of PAGE.

Here is the code I'm using:

ODS PDF FILE="H:\PLOT.PDF";
ODS GRAPHICS ON;
ODS LISTING CLOSE;
goptions ftext='Helvetica' device=pdfc;
PROC GPLOT DATA=ADDN ANNOTATE=ANNO;
by page;
PLOT num * rate /
HREF=staterate chref=red
HAXIS=AXIS1
VAXIS=AXIS2
ANNO=ANNO;
FORMAT num hospname.;
run;
quit;
ODS GRAPHICS OFF;
ODS PDF CLOSE;
ODS LISTING;

What am I not doing right?
SAS Super FREQ
Posts: 8,862

Re: Using ODS for a multi-page GPLOT

Posted in reply to deleted_user
Hi,
Well, for one thing you do NOT need the ODS GRAPHICS ON/OFF statements. They have no impact on "classic" SAS/Graph procedures like PROC GPLOT. The only time you need to use ODS GRAPHICS ON/OFF are with SAS/STAT procedures that will automatically produce ODS graph output from graph template-based procedures and to set options for the SG procedures. But since those statements will be ignored by device-based procedures, like GPLOT, it's not a big deal....just something to correct when you're fixing up the code.

Without seeing the data, I'm wondering whether num and rate are somehow the same for each "page" or what there is about the data that should make each "page" different, but somehow does not. What does the PAGE variable represent???? How did it get set??? Are you sure that NUM and RATE are different for each value of PAGE????

When I run the program below, I get 3 pages, as I expect.

cynthia
[pre]
data addn;
set sashelp.shoes;
where region in ('Asia', 'Canada', 'Pacific');
num = sales;
rate = returns;
if region = 'Asia' then page = 1;
else if region = 'Canada' then page = 2;
else if region = 'Pacific' then page = 3;
run;

proc sort data=addn;
by page;
run;

options orientation=landscape;
ODS LISTING CLOSE;
ODS PDF FILE="c:\temp\PagePlot.PDF";
goptions ftext='Helvetica' device=pdfc;

title 'Test "PAGE" as by variable';
PROC GPLOT DATA=ADDN;
by page;
PLOT num * rate ;
run;
quit;

ODS PDF CLOSE;
ODS LISTING;
[/pre]
N/A
Posts: 0

Re: Using ODS for a multi-page GPLOT

Posted in reply to Cynthia_sas
The problem is caused by an ORDER statement when I create the annotate dataset. I can work around that. Thank you for your help.

Sylvia
N/A
Posts: 0

Re: Using ODS for a multi-page GPLOT

Posted in reply to Cynthia_sas
I'm using an annotate dataset to display confidence intervals, following code described in this paper: http://www2.sas.com/proceedings/sugi29/035-29.pdf.

The rate is plotted on all pages of the GPLOT output, but the confidence interval, defined in the annotate dataset, is plotted only on the first page.

Here is the code I'm using:

DATA ANNO;
LENGTH COLOR $8 FUNCTION $8;
RETAIN XSYS '2' YSYS '2';
SET ADDN;
by page;
if rate ^= . then do;
FUNCTION='MOVE'; XSYS='2'; YSYS='2'; X=LB; Y=num; OUTPUT;
FUNCTION='DRAW'; XSYS='2'; YSYS='2'; X=UB; Y=num; COLOR='BLUE'; LINE=1; SIZE=1; OUTPUT;
FUNCTION='DRAW'; XSYS='2'; YSYS='8'; X=UB; Y=+.1; COLOR='BLUE'; LINE=1; SIZE=1; OUTPUT;
FUNCTION='DRAW'; XSYS='2'; YSYS='8'; X=UB; Y=-.2; COLOR='BLUE'; LINE=1; SIZE=1; OUTPUT;
FUNCTION='MOVE'; XSYS='2'; YSYS='2'; X=LB; Y=num; COLOR='BLUE'; LINE=.; SIZE=.; OUTPUT;
FUNCTION='DRAW'; XSYS='2'; YSYS='8'; X=LB; Y=+.1; COLOR='BLUE'; LINE=1; SIZE=1; OUTPUT;
FUNCTION='DRAW'; XSYS='2'; YSYS='8'; X=LB; Y=-.2; COLOR='BLUE'; LINE=1; SIZE=1; OUTPUT;
end;

I get the following message for each observation/annotation not on the first page:

NOTE: ERROR DETECTED IN ANNOTATE= DATASET WORK.ANNO.
NOTE: PROBLEM IN OBSERVATION 91 -
DATA SYSTEM REQUESTED, BUT VALUE IS NOT ON GRAPH 'Y'

How can I apply the annotate dataset to all pages?
Super Contributor
Super Contributor
Posts: 3,174

Re: Using ODS for a multi-page GPLOT

Posted in reply to deleted_user
From the SAS-hosted DOC, there is some specific direction when using a BY statement to consider:

http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#/documentation/cd...

Scott Barry
SBBWorks, Inc.

Google advanced search argument, this topic / post:

gpolt annotate by variable site:sas.com
N/A
Posts: 0

Re: Using ODS for a multi-page GPLOT

Posted in reply to deleted_user
PROC GPLOT is creating all the pages, plotting all the rates, labeling the values of NUM correctly and drawing the reference line specified in the statement "HREF=staterate chref=red;".

It is drawing the confidence interval, specified in the ANNOTATE dataset, only on the first page. The code for this follows the example in http://www2.sas.com/proceedings/sugi29/035-29.pdf:

if rate ^= . then do;
* A. Position the device at the lower bound of the symbol;
FUNCTION='MOVE'; XSYS='2'; YSYS='2'; X=LB; Y=num; OUTPUT;
* B. Create a blue, solid, thin line from the lower bound to the upper bound;
FUNCTION='DRAW'; XSYS='2'; YSYS='2'; X=UB; Y=num; COLOR='BLUE'; LINE=1; SIZE=1; OUTPUT;
* C. Draw the top portion of the upper bound vertical axis;
FUNCTION='DRAW'; XSYS='2'; YSYS='8'; X=UB; Y=+.1; COLOR='BLUE'; LINE=1; SIZE=1; OUTPUT;
* D. Draw the bottom portion of the upper bound vertical axis;
FUNCTION='DRAW'; XSYS='2'; YSYS='8'; X=UB; Y=-.2; COLOR='BLUE'; LINE=1; SIZE=1; OUTPUT;
* E. Position the device at the lower bound of the symbol and clear out the variables that don’t relate to the function being used in order to make debugging easier;
FUNCTION='MOVE'; XSYS='2'; YSYS='2'; X=LB; Y=num; COLOR='BLUE'; LINE=.; SIZE=.; OUTPUT;
* F. Draw the top portion of the lower bound vertical axis;
FUNCTION='DRAW'; XSYS='2'; YSYS='8'; X=LB; Y=+.1; COLOR='BLUE'; LINE=1; SIZE=1; OUTPUT;
* G. Draw the bottom portion of the lower bound vertical axis;
FUNCTION='DRAW'; XSYS='2'; YSYS='8'; X=LB; Y=-.2; COLOR='BLUE'; LINE=1; SIZE=1; OUTPUT;
end;

It is also labeling the rate, specified in the ANNOTATE dataset, but only on the first page.

* H. Label rates;
if id = '000000' then rate_label = '2008 state rate: '||put(rate,5.2);
else if rate = . then do;
rate_label = 'Fewer than 30 cases';
FUNCTION='LABEL'; XSYS='2'; YSYS='2';
x = 2; Y=num;
FONT='HELVETICA'; SIZE=.5; COLOR='BLACK'; TEXT=rate_label;
POSITION='5'; OUTPUT;
end;
else if rate ^= . then do;
rate_label = put(rate,5.2);
FUNCTION='LABEL'; XSYS='2'; YSYS='2';
x = 2; Y=num;
FONT='HELVETICA'; SIZE=.5; COLOR='BLACK'; TEXT=rate_label;
POSITION='5'; OUTPUT;
end;

How can I get the annotate dataset to apply to more than the first page?
SAS Super FREQ
Posts: 8,862

Re: Using ODS for a multi-page GPLOT

Posted in reply to deleted_user
Hi:
The paper that you reference did NOT use BY group processing. In order to successfully convert from that program to a program that used BY group processing, the following changes might have needed to be made:

beginquote

Using BY-Group Processing with the Annotate Facility

You can use the Annotate facility with procedures that use BY statements to annotate each graph that is generated with a BY statement. The Annotate graphics for each graph are generated depending on the value of the BY variable. To use BY-group processing with the Annotate facility, your program must meet the following conditions:

--Both the input data set for the procedure and the Annotate data set must contain the same BY variable.

--The BY variable must be defined as the same type (character or numeric) and length in both data sets.

--If a label or format is associated with a BY variable in one data set, the same label or format has to be associated with it in the other data set.

--Both data sets must be sorted by the BY variable.

--The ANNOTATE= option must be specified in an action statement in the procedure. If you specify the ANNOTATE= option in the PROC statement, the Annotate graphics are used for all graphs that are generated by the procedure rather than for unique values of the BY variable.

endquote
from documentation topic:
http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#/documentation/cd...


If you have followed all the conditions, as set forth in the above section from the documentation and your GPLOT and ANNOTATE are not working correctly, then you should consider opening a track with Tech Support. They can look at ALL your code and ALL your data and help you determine what might be causing the issue. To open a track with Tech Support, fill out the form at this link:
http://support.sas.com/ctx/supportform/createForm

cynthia
N/A
Posts: 0

Re: Using ODS for a multi-page GPLOT

Posted in reply to deleted_user
The problem turned out to be in how I had the PROC GPLOT statement set up:

PROC GPLOT DATA=ADDN ANNOTATE=ANNO;
by page;
PLOT num * rate /
HREF=staterate chref=red
HAXIS=AXIS1
VAXIS=AXIS2
ANNO=ANNO;
FORMAT num hospname.;

When I removed ANNOTATE=ANNO from the PROC statement it worked.
ANNO=ANNO in the PLOT statement applies the BY statement to the annotate dataset.
SAS Super FREQ
Posts: 8,862

Re: Using ODS for a multi-page GPLOT

Posted in reply to deleted_user
Hi,
That makes sense. The PLOT statement -is- the ACTION statement referred to in the documentation where it says:

--The ANNOTATE= option must be specified in an action statement in the procedure. If you specify the ANNOTATE= option in the PROC statement, the Annotate graphics are used for all graphs that are generated by the procedure rather than for unique values of the BY variable.


cynthia
Ask a Question
Discussion stats
  • 8 replies
  • 249 views
  • 0 likes
  • 3 in conversation