BookmarkSubscribeRSS Feed
wkossack
Calcite | Level 5
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
;
13 REPLIES 13
DanH_sas
SAS Super FREQ
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]
wkossack
Calcite | Level 5
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
DanH_sas
SAS Super FREQ
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?
wkossack
Calcite | Level 5
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
DanH_sas
SAS Super FREQ
Use the NOVARNAME option on the PANELBY statement to get rid of the variable label.
wkossack
Calcite | Level 5
OK that worked but I have not gotten colaxis to work

I'm using

COLAXIS values=(90 to 100 by 1) ;
DanH_sas
SAS Super FREQ
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
wkossack
Calcite | Level 5
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
DanH_sas
SAS Super FREQ
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]
wkossack
Calcite | Level 5
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.
DanH_sas
SAS Super FREQ
Secondary axis support for DATALATTICE was added in SAS 9.2m3. What version of SAS 9.2 do you have?
wkossack
Calcite | Level 5
EG 4.2
wkossack
Calcite | Level 5
ah there it is 9.2M1

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
  • 13 replies
  • 3634 views
  • 0 likes
  • 2 in conversation