BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pau13rown
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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

 

 

View solution in original post

6 REPLIES 6
Reeza
Super User
Can you drop down to GTL?
pau13rown
Lapis Lazuli | Level 10

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

Reeza
Super User

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

 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=grstatug&docsetTarget=tit...

 

There's at least one or two examples on creating a lattice/panel that I see on that page.

Rick_SAS
SAS Super FREQ

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

 

 

DanH_sas
SAS Super FREQ

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?

pau13rown
Lapis Lazuli | Level 10

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 1168 views
  • 10 likes
  • 4 in conversation