Hi SAS Community!
I'm trying to produce waterfall plots with extremely different sample sizes for 2 treatment groups. The problem is that width of the bars differs a lot in the case with very different sample sizes. I'm trying to place bars in the center for the group with small sample size using big offsets and minimize the barwidth but I faced the problem that SAS aligns boundary ticks one under other:
I need to minimize offsets for the bottom layout while save offsets for the top layout. As on the image below:
But sas ignores offsets options and takes a maximum of the offsets from top and bottom layout.
Below please see sas code used to produce outputs:
data sample;
do x = 1 to 5;
y = ranuni(0)*100;
output;
end;
do x2 = 1 to 20;
y2 = ranuni(0)*100;
output;
end;
run;
proc template;
define statgraph Statgraph.test;
begingraph;
layout lattice / rows=2 columns=1;
layout overlay / xaxisopts=(offsetmin=.35 offsetmax=.35);
barchart x=x y=y;
endlayout;
layout overlay / xaxisopts=(offsetmin=.05 offsetmax=.05);
barchart x=x2 y=y2;
endlayout;
endlayout;
endgraph;
end;
run;
ods html;
proc sgrender data=sample template=Statgraph.test;
run;
Options for layout lattice as rowdatarange do not affect on graphs. Seems that the problem is related to discrete axis type which is the only type allowed for barchart. Could anyone help with this problem? Thanks.
Kind regards!
Break the "sibling" relationship by adding a LAYOUT GRIDDED around the second LAYOUT OVERLAY.
proc template;
define statgraph Statgraph.test;
begingraph;
layout lattice / rows=2 columns=1;
layout overlay / xaxisopts=(offsetmin=.35 offsetmax=.35);
barchart x=x y=y;
endlayout;
layout gridded;
layout overlay / xaxisopts=(offsetmin=.05 offsetmax=.05);
barchart x=x2 y=y2;
endlayout;
endlayout;
endlayout;
endgraph;
end;
run;
I'm not sure how you intend to use this display, but consider whether you can add a group variable and then call the SGPANEL procedure to plot both groups in a column. The SGPANEL procedure supports many options for equating or not equating axes.
data sample;
group = 1;
do x = 1 to 5;
y = ranuni(123)*100;
output;
end;
group = 2;
do x = 1 to 20;
y = ranuni(123)*100;
output;
end;
run;
proc sgpanel data=sample;
panelby group / columns=1;
vbar x / response=y;
run;
Hi Rick,
Thank you for the quick reply, your solution works but I need something which will work with my approach, I have very "big" macro and it will consume a huge amount of time to rewrite using your approach
Break the "sibling" relationship by adding a LAYOUT GRIDDED around the second LAYOUT OVERLAY.
proc template;
define statgraph Statgraph.test;
begingraph;
layout lattice / rows=2 columns=1;
layout overlay / xaxisopts=(offsetmin=.35 offsetmax=.35);
barchart x=x y=y;
endlayout;
layout gridded;
layout overlay / xaxisopts=(offsetmin=.05 offsetmax=.05);
barchart x=x2 y=y2;
endlayout;
endlayout;
endlayout;
endgraph;
end;
run;
Since you mention waterfall plots, you might want to look at the article "Create a waterfall chart in SAS."
Sanjay has also written about this kind of chart in "Clinical Graphs."
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.