Data visualization with SAS programming

side by side bars with SGPLOT

Reply
Contributor
Posts: 29

side by side bars with SGPLOT

how can I get bars groups placed side by side with sgplot like you get from gplot

PROC GCHART DATA=sumsboth;
VBAR Lag / discrete TYPE=SUM SUMVAR=percent_success_both GROUP=year_quarter ref=99 frontref cref=red
FRAME
COUTLINE=BLACK
RAXIS=AXIS1
MAXIS=AXIS2
PATTERNID=MIDPOINT
;
SAS Super FREQ
Posts: 925

Re: side by side bars with SGPLOT

For SAS 9.2, you have to be a little creative. For SAS 9.3, there will be an option to get side-by-side groups in SGPLOT. In the meantime, try this example below. Your group variable will go on the PANELBY statement. There are other options on the PANELBY statement to move the column headings (columnheaderpos) and to remove the label part of the column heading (novarlabel).

Hope this helps,
Dan

[pre]
proc sgpanel data=sashelp.class;
panelby sex / layout=columnlattice onepanel noborder;
vbar age / response=height;
run;
[/pre]
Contributor
Posts: 29

Re: side by side bars with SGPLOT

close except for a couple things

my value for year_quarter is truncated to just 20

also they want the vertical scale adjusted as
yaxis values=(90 91 93 94 95 96 97 98 100);
would affect the scale with sgplot

I don't see any way of doing that with sgplanel

Message was edited by: wkossack Message was edited by: wkossack
SAS Super FREQ
Posts: 925

Re: side by side bars with SGPLOT

The VALUES option can be specified on the ROWAXIS statement to control the scaling of the vertical axis. Was the trucation on the axis or the column headings?
Contributor
Posts: 29

Re: side by side bars with SGPLOT

column headings.

I think there is not enough space. I looked up the ROWAXIS. All I really need is for the value to be displayed not the variable name i.e. 2010_Q1 not year_quarter = 2010_Q1
SAS Super FREQ
Posts: 925

Re: side by side bars with SGPLOT

Use the NOVARNAME option on the PANELBY statement to get rid of the variable label.
Contributor
Posts: 29

Re: side by side bars with SGPLOT

OK that worked but I have not gotten colaxis to work

I'm using

COLAXIS values=(90 to 100 by 1) ;
SAS Super FREQ
Posts: 925

Re: side by side bars with SGPLOT

You need to use the ROWAXIS statement instead of the COLAXIS statement. The row axes are the vertical axes and and the column axes are the horizontal axes.

Thanks!
Dan
Contributor
Posts: 29

Re: side by side bars with SGPLOT

Arg....should have realized that

is there any way I can overlay a line plot with sgpanel?

I have another variable I want to overlay with an additional vertical axis. For example, my bars are the percent error but I want to overlay a line that is the sample size
SAS Super FREQ
Posts: 925

Re: side by side bars with SGPLOT

You can overlay a VLINE chart on the VBAR chart; however, we do not currently support secondary axes for SGPANEL. For the time being, you can use GTL to do it. Here is an example:

[pre]
proc template;
define statgraph barline;
begingraph /;
layout gridded / rowgutter=5;
layout datalattice columnvar=Sex / includeMissingClass=false rowDataRange=unionall columnDataRange=unionall rows=1
rowAxisOpts=( offsetmin=0 display=all altdisplay=all linearOpts=( viewmin=0 ))
columnAxisOpts=(type=Discrete display=all altdisplay=all)
row2AxisOpts=( offsetmin=0 display=all altdisplay=all linearOpts=( viewmin=0 ));
layout prototype / wallDisplay=(fill);
ReferenceLine y=0 / lineattrs=GraphAxisLines;
BarChart X=Age Y=Height / primary=true LegendLabel="Height" NAME="VBAR";
SeriesPlot X=Age Y=Weight / LegendLabel="Weight" yaxis=y2 NAME="VLINE";
endlayout;
endlayout;
DiscreteLegend "VBAR" "VLINE";
endlayout;
endgraph;
end;
run;

proc summary data=sashelp.class nway;
class sex age;
var weight height;
output out=temp mean=;
run;

proc sgrender data=temp template=barline; run;
[/pre]
Contributor
Posts: 29

Re: side by side bars with SGPLOT

this generates a number of errors

for starters

rowAxisOpts=( offsetmin=0 display=all altdisplay=all linearOpts=( viewmin=0 ))
___________
180
42 ! columnAxisOpts=(type=Discrete display=all altdisplay=all) row2AxisOpts=( offsetmin=0 display=all altdisplay=all
42 ! linearOpts=( viewmin=0 )); layout prototype / wallDisplay=(fill); ReferenceLine y=0 /

ERROR 180-322: Statement is not valid or it is used out of proper order.
SAS Super FREQ
Posts: 925

Re: side by side bars with SGPLOT

Secondary axis support for DATALATTICE was added in SAS 9.2m3. What version of SAS 9.2 do you have?
Contributor
Posts: 29

Re: side by side bars with SGPLOT

EG 4.2
Contributor
Posts: 29

Re: side by side bars with SGPLOT

ah there it is 9.2M1
Ask a Question
Discussion stats
  • 13 replies
  • 1540 views
  • 0 likes
  • 2 in conversation