BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sspkmnd
Obsidian | Level 7

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:

 

win7-amd64-sas94-vbox [Работает] - Oracle VM VirtualBox 2016-01-19 16.27.10.png

I need to minimize offsets for the bottom layout while save offsets for the top layout. As on the image below:

 

win7-amd64-sas94-vbox [Работает] - Oracle VM VirtualBox 2016-01-19 16.34.51.png


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!

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

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;

 

WaterfallPanel.png

View solution in original post

4 REPLIES 4
Rick_SAS
SAS Super FREQ

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;

SGPanel2.png

 

sspkmnd
Obsidian | Level 7

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

Jay54
Meteorite | Level 14

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;

 

WaterfallPanel.png

Rick_SAS
SAS Super FREQ

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 4 replies
  • 1221 views
  • 3 likes
  • 3 in conversation