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.
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.
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');
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.
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.)
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.
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;
Xaxis values=(0 to 5 by 1) DISPLAY=(nolabel) DISCRETEORDER=DATA;
vbar product /datalabel response=sales fillattrs=(color=cx3366ff);
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:
1142 %put &sysvlong4;
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.
**get exactly 4 regions for testing;
proc sort data=sashelp.shoes out=shoes;
where region in ('Asia', 'Africa', 'Eastern Europe', 'Western Europe');
** 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;
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.