How do I make a bar chart with N on the y-axis, a category on the x-axis and percent as a label on the bars without creating an output data set with proc freq or something similiar. Just using raw data. . .
Thank you.
The hacky method that comes to mind is overlaying two plots, one with invisible bars that shows the percentages on a non-shown dual axis. So the labels will come from one plot and the data/bars from another. You will need to customize your legend using keylegend - I'm leaving that for you.
proc sgplot data=sashelp.class;
hbar sex / stat=freq;
hbar sex / stat=percent x2axis datalabel nooutline;
x2axis display=none;
run;
@telligent wrote:
How do I make a bar chart with N on the y-axis, a category on the x-axis and percent as a label on the bars without creating an output data set with proc freq or something similiar. Just using raw data. . .
Thank you.
FYI - replace HBAR with VBAR and X2AXIS with Y2AXIS for a vertical layout.
The hacky method that comes to mind is overlaying two plots, one with invisible bars that shows the percentages on a non-shown dual axis. So the labels will come from one plot and the data/bars from another. You will need to customize your legend using keylegend - I'm leaving that for you.
proc sgplot data=sashelp.class;
hbar sex / stat=freq;
hbar sex / stat=percent x2axis datalabel nooutline;
x2axis display=none;
run;
@telligent wrote:
How do I make a bar chart with N on the y-axis, a category on the x-axis and percent as a label on the bars without creating an output data set with proc freq or something similiar. Just using raw data. . .
Thank you.
FYI - replace HBAR with VBAR and X2AXIS with Y2AXIS for a vertical layout.
Thank you!
proc sgplot data=one noautolegend;
vbar q1 / stat=freq;
xaxis display=(nolabel) ;
vbar q1 /stat=percent x2axis datalabel nooutline;
x2axis display=none;
yaxis integer max=&n;
run;
I noticed the statement below that I added throws the whole thing off. When I do this the bar heights are wrong relative to the y axis. Do you have any suggestions for me? I want the y-axis to go up to a certain level and the bar heights to still be correct. Thank you.
yaxis integer max=100;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.