- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to create a stacked bar chart with proc template and sgrender
but the variable that i want on the top part of the stack will only work on the bottom:
i have
barchart x=a y=b
barchart x=a y= c
I want it to be c on top but it only works with b on top.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I was able to figure it out where I could have total of c+b as the first y variable, and then b on the bottom as the second variable.
in proc template
xaxis
yaxia
barchart x= y=total
barchart x= y=bottomamount
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
show your entire code and some example data to show the result you get and hopefully some way to show what you want to get (image is fine PNG, GIF what ever, Excel not so fine)
Order of statements in the template, order of data and data values may have some pretty complex interactions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Proc template;
define statgraph Graph;
begingraph;
layout overlay/
xaxisopts=(name = 'bin_label' label='a' labelattrs=(size=12pt weight=bold)tickvalueattrs=(size=10))
yaxisopts=(name = 'b' label='b' linearopts=(tickvalueformat=comma8.) labelattrs=(size=12pt weight=bold)tickvalueattrs=(size=10))
y2axisopts=(name='pct_row' label='c' labelattrs=(size=12pt weight=bold)tickvalueattrs=(size=10));
barchart x= a. y=b/ fillattrs=(color=lightgreen) name='data1' barwidth=0.65 barlabelattrs=(size=10pt);
barchart x= a y=c / fillattrs=(color=gold) name='data2'' barwidth=0.65 barlabelattrs=(size=10pt );
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data is?
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
And the sgrender code used is?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
While you say "Stacked" bar chart, you are showing code that will generate "Overlaid" bars. Since y=c is specified later, it will be drawn later, overlaid on the y=b bar. The bar charts are drawn in the order you specify them. If you want y=b layered on top, put it later in the code.
This bar chart is not "Stacked". To get a stacked bar chart, use the GROUP option. The group values will be stacked by default. To get side-by-side bars, use GROUPDISPLAY=CLUSTER.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, but the variables are really able to be grouped. they are two separate columns
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
IMO it's easier to restructure data than to modify a template.
@emcw wrote:
Thanks, but the variables are really able to be grouped. they are two separate columns
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Are you trying to stack C on top of B in the same bar?
DATA PLEASE.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes that's right. Id prefer not to share the data
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@emcw wrote:
Yes that's right. Id prefer not to share the data
MAKE FAKE DATA. We don't need real data, just data that looks like what your is and can mimic it. We all have confidential information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Unlike Excel, two separate columns cannot be stacked in GTL or SGPLOT. You can place them side by side using DISCRETEOFFSET. To stack the values, you have to change the structure, and convert the 2-column data into a group and response data. You can use PROC TRANSPOSE, or just Data Step as below.
data b;
set a;
keep a Group Value;
Group='B'; Value=b; output;
Group='C'; Value=c; output;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The group won't work because I need the count.
for example
c=4,9,5,8
b=2,1,3,2
with b on top, the one with lower value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It would be easier and faster to help if you include a picture of what you want, and your code with a (fake) data set (in code). Which release of SAS are you using?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
somthing like this.
with c=4,5,7,8
b=2,1,3,1
i was thinking i could have totalbc as a new variable, then group=c, group=b but the grouping isn't working
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
See this article on how to create such a graph. The data needs to be in "Grouped" form as in SASHELP.PRDSALE.