i like this blog post by Sanjay Matange (@sanjay1 ?) https://blogs.sas.com/content/graphicallyspeaking/2014/01/18/two-in-one-graph/#prettyPhoto
but how can i create a grid of such plots e.g. if i want a grid with 4 cells and each cell contains the kind of plot Sanjay has produced. Proc sgpanel does not allow the yaxis2 which achieves Sanjay's plot, and sgplot does not allow a panel. Thus, how to achieve both features...? cheers
You can use the ODS LAYOUT GRIDDED statement to assemble graphs (and/or tables) into a gridded arrangement. See
https://blogs.sas.com/content/sasdummy/2015/11/23/ods-statement-options-to-change/
and a few additional comments in
https://blogs.sas.com/content/iml/2015/12/02/matrices-graphs-gridded-layout.html
i'm trying to read up on gtl, given your suggestion, but the info out there seems scattered and incomplete. Eg, i generated my figure using sgplot. How do i now gain access to the proc template code which needs to be modified and is apparently hiding in the background somewhere? I ought to use that code as a starting point, if it's at all possible to create the fig as i want it. There are papers like this: http://support.sas.com/rnd/app/ODSGraphics/papers/modtmplt.pdf which imply that it's rather easy to obtain the source code, but what they suggest amounts to nothing.... cheers
@pau13rown wrote:
i'm trying to read up on gtl, given your suggestion, but the info out there seems scattered and incomplete. Eg, i generated my figure using sgplot. How do i now gain access to the proc template code which needs to be modified and is apparently hiding in the background somewhere? I ought to use that code as a starting point, if it's at all possible to create the fig as i want it. There are papers like this: http://support.sas.com/rnd/app/ODSGraphics/papers/modtmplt.pdf which imply that it's rather easy to obtain the source code, but what they suggest amounts to nothing.... cheers
Did you try the TMPLOUT out option on SGPLOT?
proc sgplot data=sashelp.cars tmplout='/folders/myfolders/demo.txt';
scatter x=mpg_highway y=mpg_city / group=origin;
run;
Generated code:
proc template;
define statgraph sgplot;
begingraph / collation=binary;
layout overlay / xaxisopts=(labelFitPolicy=Split) x2axisopts=(labelFitPolicy=Split);
ScatterPlot X=MPG_Highway Y=MPG_City / subpixel=off primary=true Group=Origin LegendLabel="MPG (City)" NAME="SCATTER";
DiscreteLegend "SCATTER"/ title="Origin";
endlayout;
endgraph;
end;
run;
I find the documentation pretty thorough, but you do need to use the most recent versions, SAS 9.2 is about a decade old.
There's at least one or two examples on creating a lattice/panel that I see on that page.
You can use the ODS LAYOUT GRIDDED statement to assemble graphs (and/or tables) into a gridded arrangement. See
https://blogs.sas.com/content/sasdummy/2015/11/23/ods-statement-options-to-change/
and a few additional comments in
https://blogs.sas.com/content/iml/2015/12/02/matrices-graphs-gridded-layout.html
One other alternative is to use ODS LAYOUT to create your 2x2 arrangement. That way, you can still use SGPLOT four times to create each plot, but have ODS arrange them 2x2 on the page. Would that work for you?
excellent answers. I'll try all 3 approaches and report back....
i decided to use the "ods layout gridded" and it worked well. My code looks like this:
ods pdf file="...\figure4.pdf";
title j=c h=1 "Figure 4. ....";
footnote ;
ods layout gridded columns=2;
ods region height=2.5in;
title ;
proc sgplot data=fig4 (where=(cohort=1)) noautolegend;
format cohort cohort_f. ...;
:
run;
ods region height=2.5in;
title ;
proc sgplot data=fig4 (where=(cohort=2)) noautolegend;
:
:
etc
and this image looks like this: figure. I guess if i played around with it more i could create a tiff file instead of pdf, and refine it in other ways
cheers
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.