🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 12-14-2018 04:52 PM
(5499 views)
Hi!
I am looking to make a bar chart that is grouped. The tricky part is that I want the datalabels to have both the count and the percent. Below is a picture of what I am looking to make (I used excel to make this). Below that is the code for example data I would like to use to make the attached bar chart.
data bar;
infile datalines delimiter=",";
input letter $ group1 group2 group3;
datalines;
A, 3, 2, 2
B, 2, 3, 1
C, 0, 1, 0
;
run;
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Come to think of it, it was not that complicated. This code
data bar;
infile datalines dlm=',';
input letter $ group1 group2 group3;
datalines;
A,3,2,2
B,2,3,1
C,0,1,0
;
run;
proc transpose data=bar out=barlong(rename=(_NAME_=Group COL1=value));
by letter;
run;
proc sql;
create table GraphData as
select *,
cats(value, "(", put(value/(sum(value)), percent.), ")") as datalabel
from barlong
group by Group;
quit;
proc sgplot data=GraphData noautolegend noborder;
vbar Group / response=value group=letter groupdisplay=cluster datalabel=datalabel;
keylegend / position=e title="" noborder;
yaxis grid display=(nolabel);
xaxis display=(nolabel);
run;
Gives you this
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can draw the bar chart doing something like below. About having counts and percentages as datalabels, it can be done, but not directly in PROC SGPLOT I believe. Are you still interested?
data bar;
infile datalines dlm=',';
input letter $ group1 group2 group3;
datalines;
A,3,2,2
B,2,3,1
C,0,1,0
;
run;
proc transpose data=bar out=barlong(rename=(_NAME_=Group COL1=value));
by letter;
run;
proc sgplot data=barlong noautolegend noborder;
vbar Group / response=value group=letter groupdisplay=cluster datalabel;
keylegend / position=e title="" noborder;
yaxis grid display=(nolabel);
xaxis display=(nolabel);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Come to think of it, it was not that complicated. This code
data bar;
infile datalines dlm=',';
input letter $ group1 group2 group3;
datalines;
A,3,2,2
B,2,3,1
C,0,1,0
;
run;
proc transpose data=bar out=barlong(rename=(_NAME_=Group COL1=value));
by letter;
run;
proc sql;
create table GraphData as
select *,
cats(value, "(", put(value/(sum(value)), percent.), ")") as datalabel
from barlong
group by Group;
quit;
proc sgplot data=GraphData noautolegend noborder;
vbar Group / response=value group=letter groupdisplay=cluster datalabel=datalabel;
keylegend / position=e title="" noborder;
yaxis grid display=(nolabel);
xaxis display=(nolabel);
run;
Gives you this