BookmarkSubscribeRSS Feed
Fisher
Quartz | Level 8
Hi All,

I know SAS output the graph one per page by default. I googled the web and found some resource to create multiple graphs on one page.

But I can't get much useful information about how to create multiple graphs (eg. 2 graphs per page) on multiple pages dynamically depending on the number of obs in the dataset.

I tried 'ODS layout' option, but this option is experimental and only available after version 9.
I also tried 'ODS PDF file=... startpage=never', but for somehow it didn't work either.

Thanks for any help!
12 REPLIES 12
Cynthia_sas
SAS Super FREQ
Hi:
I guess I don't understand what you mean when you say: " how to create multiple graphs (eg. 2 graphs per page) on multiple pages dynamically depending on the number of obs in the dataset" -- I'm not sure what the number of obs in the dataset have to do with anything. You are generating 1 graph per observation??? You are using BY group processing and sometimes you have 4 BY groups and sometimes you have 8 BY groups in the data????

Before ODS LAYOUT, how people got 2 graphs per page was to use PROC GREPLAY, possibly with a SAS Macro program to create and then replay graphs as needed. But without more details, it's hard to say whether that approach would work for you. I'm not sure that ODS LAYOUT will be quite so flexible although it should work with SAS Macro processing.

cynthia
Fisher
Quartz | Level 8
Thanks Cynthia.
You are kind of right. the number of page is determined by the number of the obs in the dataset. I use the macro to loop the dataset and determine the number of page. I like to create two pies per page.
Here is my macro code, but it didn't create what I expected.

ODS listing close;
option nodate nonumber orientation=portrait;
ODS pdf file ="C:\test\test.pdf" startpage=never;
ODS GRAPHICS/NOBORDER;


goptions reset=all device=pdfc hsize=5.2in vsize=5.2in;

data _null_;
set test.role_loop end=last;
call symputx('FN'||strip(left(put(_N_,8.))), Facility_Name, 'L');
call symputx('Denom'||strip(left(put(_N_,8.))), Denom, 'L');
if last then call symputx('count', _N_, 'L');
run;

title3 'Role Description';


%do i=1 %to &count;
%if %sysfunc(mod(&i, 2))=1 %then %do;
goptions horigin=0.1in vorigin=%eval((&i-1)*5)in;
TITLE;
FOOTNOTE;
%end;
%else %do;
goptions vorigin=5in;
%end;

title5 "&&FN&i";


proc gchart data=test.HTVI_Role(where=(Facility_Name="&&FN&i"));
format Role $piefmt.;
pie Role /sumvar=rate
other=0
midpoints='Missing' 'LPN' 'RN'

value=none
percent=arrow
slice=arrow
noheading;

run;
quit;
%end;

ODS pdf close;

Message was edited by: Fisher

Message was edited by: Fisher Message was edited by: Fisher
Cynthia_sas
SAS Super FREQ
Hi:
Well, let's take a step back and just look at what you can do without MACRO or GREPLAY and using only COLUMNS=2 -- with SAS/GRAPH and SAS 9.2. I get 2 pies per page and 2 pages (since I have 4 regions) with the program below.

I am not sure that you need to go down the macro road just yet, until you have figure out whether simple BY group processing and COLUMNS=2 (in SAS 9.2) will work for you.

Next, you may want to explore ODS LAYOUT, as described in this paper:
http://www.wuss.org/proceedings09/09WUSSProceedings/papers/dpr/DPR-OConnor.pdf

Or, you may want to investigate some of the Macro and GREPLAY examples at this web site (which has many, many wonderful SAS/GRAPH examples):
http://www.robslink.com/SAS/Home.htm (when you drill down into one of the 48 major topics, you will see thumbnails of all the examples under that topic. From the thumbnail link, you can see a bigger picture and also download the code that created the example.)

cynthia
[pre]
ODS listing close;
option nodate nonumber orientation=landscape nobyline
topmargin=.25in bottommargin=.25in rightmargin=.25in leftmargin=.25in;

proc sort data=sashelp.shoes out=shoes;
where region in ('Asia', 'Canada', 'Pacific', 'Western Europe');
by region;
run;

ODS pdf file ="C:\temp\test.pdf" columns=2;
ODS GRAPHICS/NOBORDER;
ods pdf text=' ';
goptions reset=all device=pdfc hsize=4.0in vsize=4.0in;

proc gchart data=shoes;
title '#byval1';
by region;
pie product /sumvar=sales
noheading;
run;
quit;

ODS pdf close;
[/pre]
Fisher
Quartz | Level 8
Thanks Cynthia.
But how to use goption orientation = portrait and display the two graphs vertically?

BTW, goption layout does't work in my SAS (SAS 9.2 TS Level 1M0), I tried to use it before current way. Message was edited by: Fisher
Cynthia_sas
SAS Super FREQ
Hi:
My technique does not use ODS LAYOUT. But this worked for me to get 2 vertical graphs on 2 pages (for 4 regions) using SAS 9.2. I think the key is making sure that the HSIZE and VSIZE are set correctly so that 2 of the images will fit on an 8 1/2 x 11 page, taking the margins into account.

BTW, the ODS GRAPHICS statement does NOT have any impact on traditional device-based SAS/GRAPH procedures, so I should have taken it out of the previous code.

cynthia
[pre]
** generates 2 pages in SAS 9.2;
ODS listing close;
option nodate nonumber orientation=portrait nobyline
topmargin=.25in bottommargin=.25in rightmargin=.25in leftmargin=.25in;

proc sort data=sashelp.shoes out=shoes;
where region in ('Asia', 'Canada', 'Pacific', 'Western Europe');
by region;
run;

ODS pdf file ="C:\temp\test_portrait_9_2.pdf" startpage=no;

ods pdf text=' ';
goptions reset=all device=pdfc hsize=4.5in vsize=4.5in;

proc gchart data=shoes;
title '#byval1';
by region;
pie product /sumvar=sales
noheading;
run;
quit;

ODS pdf close;
[/pre]
Fisher
Quartz | Level 8
Hi Cynthia,

After I make a little bit modification to your above code to create two graphs per page, then some weird thing about title happened: from the second page, the titles of the first graph duplicate. know why?

ODS pdf file ="C:\temp\test_portrait_9_2.pdf" startpage=no;

ods pdf text=' ';
goptions reset=all device=pdfc hsize=4.5in vsize=4.5in;

proc sgplot data=sashelp.shoes;
title '#byval1';
Xaxis values=(0 to 5 by 1) DISPLAY=(nolabel) DISCRETEORDER=DATA;
yaxis label="Percent(%)";
vbar product /datalabel response=sales fillattrs=(color=cx3366ff);
by region;
run;
quit;

ODS pdf close;
Cynthia_sas
SAS Super FREQ
Hi:
I believe it is related to this Tech Support note:
http://support.sas.com/kb/34/600.html

cynthia
ArtC
Rhodochrosite | Level 12
When using #BYVAL options you may also want to use:
[pre]options nobyline;[/pre]
Cynthia_sas
SAS Super FREQ
Oh, good catch, Art. But I still see the issue from the Tech Support note, even if I use OPTIONS NOBYLINE. Run the code below -- I ran it on the following SAS system:
[pre]
1142 %put &sysvlong4;
9.02.02M3P04132010
[/pre]
and do still get a duplicated titles starting on page 2.

I do NOT see the issue in the created RTF file. Also, remember that GOPTIONS do not have any impact on ODS GRAPHICS, and that includes the SG procedures.

cynthia
[pre]
options nodate nonumber nobyline orientation=portrait nobyline
topmargin=.5in bottommargin=.5in leftmargin=.5in rightmargin=.5in;

**get exactly 4 regions for testing;
proc sort data=sashelp.shoes out=shoes;
by region;
where region in ('Asia', 'Africa', 'Eastern Europe', 'Western Europe');
run;

** create RTF and PDF to see any differences.;
** As Tech Support note indicates. Issue exists with PDF, but titles for RTF;
** are correct.;
ods rtf file="c:\temp\use_sgplot_byline.rtf" startpage=no gtitle;
ODS pdf file ="C:\temp\use_sgplot_byline.pdf" startpage=no;

ods graphics / imagefmt=png height=4.5in width=4.5in;

proc sgplot data=shoes;
title '#byval1';
Xaxis values=(0 to 5 by 1) DISPLAY=(nolabel) DISCRETEORDER=DATA;
yaxis label="Percent(%)";
vbar product /datalabel response=sales fillattrs=(color=cx3366ff);
by region;
run;

ODS _all_ close;
title;
options byline;

%put &sysvlong4;
[/pre]
Fisher
Quartz | Level 8
I have the same SAS version as Cynthia's. Cynthia is right, option nobyline doesn't resolve the problem.
Do you recommend ODS LAYOUT option? I know it is still a experimental feature.

Thanks.
Cynthia_sas
SAS Super FREQ
Hi:
I did not see the issue with ODS GRAPHICS, PROC SGPLOT and ODS RTF. If you can use "pre-production" features in your production jobs, then ODS LAYOUT might be a choice. I don't know because I don't know whether the SG procedures have the same interaction with ODS LAYOUT as the traditional SAS/GRAPH procedures do.

I would recommend that you check with Tech Support first -- there's not any point in going down the road with pre-production features of the software if it's not going to solve your problem and you're going to end up using ODS RTF anyway.

cynthia

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register 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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 12 replies
  • 5364 views
  • 0 likes
  • 3 in conversation