I have created some very nice plots using PROC SGPLOT, using the several SERIES statements, some of which use the Y2AXIS option, to generate line plots with 2 different vertical axes. Great, exactly what I wanted.
Then, I wanted 4 of these plots on a page (2 rows and 2 columns), so I switch to PROC SGPANEL which will produce this 2x2 matrix of plots, but then I discover there is no Y2AXIS option on the SERIES statement.
So, my question ... can someone recommend a workaround or alternative that can give me two different vertical axis scales in PROC SGPANEL?
I know I can do this in traditional SAS/GRAPH with templates in PROC GREPLAY, but since my code is already written in ODS GRAPHICS, I'd prefer to stay in ODS Graphics if possible.
Hi Paige,
Depending on your ODS destination, you might be able to use ODS LAYOUT GRIDDED on the original SGPLOT output. This statement was added in SAS 9.4m1. Some simple examples are:
Run the following simple example to get an idea how it works, then let us know whether this might suit your needs:
ods graphics / width=4in height=2in;
ods layout gridded columns=2 advance=table;
proc sgplot data=sashelp.stocks;
where stock="IBM";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Intel";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Microsoft";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
vbox open / category=stock;
run;
ods layout end;
Hi Paige,
Depending on your ODS destination, you might be able to use ODS LAYOUT GRIDDED on the original SGPLOT output. This statement was added in SAS 9.4m1. Some simple examples are:
Run the following simple example to get an idea how it works, then let us know whether this might suit your needs:
ods graphics / width=4in height=2in;
ods layout gridded columns=2 advance=table;
proc sgplot data=sashelp.stocks;
where stock="IBM";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Intel";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Microsoft";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
vbox open / category=stock;
run;
ods layout end;
Thanks, @Rick_SAS, this looks exactly like what I want to do. Ideally, the output is via ODS POWERPOINT. I'll take a crack at it and see if I can get it to work.
Well that was easy! Chris's example works fine with ODS POWERPOINT.
Thanks @Rick_SAS and @ChrisHemedinger.
Now I have found that I can produce one such 2x2 matrix of plots using SGPLOT and have it show up in Powerpoint via ODS POWERPOINT. Works great.
But I actually want seven different 2x2 matrices of plots, one on each page of a POWERPOINT document, and SAS crashes when I try this via a macro %DO loop to loop over all seven variables of interest. 😞
If I re-write the same loop to create seven different Powerpoint files, with one plot each, no errors and no crashes.
Performing both of the above attempts to output the plots via ODS HTML, no error and no crashes either way.
The below "unmacroized" SAS code produces expected output with 9.4M4. Sorry, the discussion software won't allow me to attach crash.pptx.
-- David Kelley
Output Delivery and Reporting
SAS
ods graphics / width=4in height=2in;
ods powerpoint file = "crash.pptx";
ods layout gridded columns=2 advance=table;
proc sgplot data=sashelp.stocks;
where stock="IBM";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Intel";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Microsoft";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
vbox open / category=stock;
run;
ods layout end;
ods powerpoint startpage=now;
ods layout gridded columns=2 advance=table;
proc sgplot data=sashelp.stocks;
where stock="IBM";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Intel";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Microsoft";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
vbox open / category=stock;
run;
ods layout end;
ods powerpoint startpage=now;
ods layout gridded columns=2 advance=table;
proc sgplot data=sashelp.stocks;
where stock="IBM";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Intel";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Microsoft";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
vbox open / category=stock;
run;
ods layout end;
ods powerpoint startpage=now;
ods layout gridded columns=2 advance=table;
proc sgplot data=sashelp.stocks;
where stock="IBM";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Intel";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Microsoft";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
vbox open / category=stock;
run;
ods layout end;
ods powerpoint startpage=now;
ods layout gridded columns=2 advance=table;
proc sgplot data=sashelp.stocks;
where stock="IBM";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Intel";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Microsoft";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
vbox open / category=stock;
run;
ods layout end;
ods powerpoint startpage=now;
ods layout gridded columns=2 advance=table;
proc sgplot data=sashelp.stocks;
where stock="IBM";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Intel";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Microsoft";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
vbox open / category=stock;
run;
ods layout end;
ods powerpoint startpage=now;
ods layout gridded columns=2 advance=table;
proc sgplot data=sashelp.stocks;
where stock="IBM";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Intel";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
where stock="Microsoft";
series x=date y=open;
series x=date y=volume / y2axis;
run;
proc sgplot data=sashelp.stocks;
vbox open / category=stock;
run;
ods layout end;
ods powerpoint close;
ods powerpoint startpage=now;
I think that's what I might have been missing.
Of course, my company is still using 9.4M2, so maybe that's the problem.
I will try these out tomorrow at work.
It appears that the STARTPAGE option of the ODS POWERPOINT command does not exist in my version SAS 9.4 TS1M2 😞
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.