Hi...I am trying to create graphs for each question and would like to have the count and percentages on each graph. The counts on each bar are correct but the percentages seem to be incorrect. Any suggestion on why the percentages might be incorrect. Thanks.
data Table12;
length Response $ 7 Term $ 9 Question $ 105 ;
format Response $char7. Term $char9. Question $char105.;
informat Response $char7. Term $char9. Question$char105.;
infile datalines4 dlm='7F'x missover dsd;
input Response : $char7. Term : $char9. Question : $char105.;
datalines4;
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I feel better prepared for the workplace because of taking this program.
MissingJune 2019I feel better prepared for the workplace because of taking this program.
MissingJune 2019I feel better prepared for the workplace because of taking this program.
NeutralJune 2019I feel better prepared for the workplace because of taking this program.
NeutralJune 2019I feel better prepared for the workplace because of taking this program.
AgreeJune 2019I had a good understanding of what I would learn in this program.
AgreeJune 2019I had a good understanding of what I would learn in this program.
AgreeJune 2019I had a good understanding of what I would learn in this program.
AgreeJune 2019I had a good understanding of what I would learn in this program.
AgreeJune 2019I had a good understanding of what I would learn in this program.
AgreeJune 2019I had a good understanding of what I would learn in this program.
AgreeJune 2019I had a good understanding of what I would learn in this program.
DisagreeJune 2019I had a good understanding of what I would learn in this program.
DisagreeJune 2019I had a good understanding of what I would learn in this program.
MissingJune 2019I had a good understanding of what I would learn in this program.
NeutralJune 2019I had a good understanding of what I would learn in this program.
NeutralJune 2019I had a good understanding of what I would learn in this program.
NeutralJune 2019I had a good understanding of what I would learn in this program.
NeutralJune 2019I had a good understanding of what I would learn in this program.
NeutralJune 2019I had a good understanding of what I would learn in this program.
NeutralJune 2019I had a good understanding of what I would learn in this program.
NeutralJune 2019I had a good understanding of what I would learn in this program.
NeutralJune 2019I had a good understanding of what I would learn in this program.
NeutralJune 2019I had a good understanding of what I would learn in this program.
;;;;
Axis1 style=1 width=1 minor=none label=(height=9pt font="arial/bold" angle=90 "Percent") value=(height=9pt font="arial" "0%" "10%" "20%" "30%" "40%" "50%" "60%" "70%" "80%" "90%" "100%");
Axis2 style=1 width=2 label=(height=9pt font="arial/bold" "Response") value=(height=9pt font="arial");
Axis3 label=(height=9pt font="arial/bold" "Term") value=(height=9pt font="arial");
proc gchart data=Table12;
vbar Response / discrete group=Term type=percent inside=percent outside=freq nolegend g100
coutline=black raxis=axis1 maxis=axis2 gaxis=axis3 woutline=1 patternid=midpoint width=20;
by Question ;
run;
quit;
I do see the problem now, the ACTXIMG bars do not appear to be to scale.
The percentage values show in the hover text is correct though.
I think the problem is your expectation more so than the Proc.
The vertical axis statement VALUE= option controls the text labels on the major tick marks but DOES NOT DEFINE those tick values. The tick values must by specified in the ORDER= option. The ACTXIMG major ticks that you are experiencing are not 0 to 100, but you are labeling them so and therein lies the confusion.
Change the AXIS statement to
Axis1 style=1 width=1 minor=none label=(height=9pt font="arial/bold" angle=90 "Percent") value=(height=9pt font="arial" "0%" "10%" "20%" "30%" "40%" "50%" "60%" "70%" "80%" "90%" "100%" )
order = 0 to 100 by 10 /* <---- need this */ ;
What percentages were you expecting to see ?
Is it possible GROUP=TERM G100 is computing percentages different than you expectation ?
The chart numbers do appear correct. These are the numbers I see
Question 1
June 2019
Response N % (fraction) Agree 15 79 15/19 Missing 2 10.5 2/19
Neutral 2 10.5 2/19
Question 2
June 2019
Agree 7 36.8 7/19
Disagree 2 10.5 2/19
Missing 1 5.3 1/19
Neutral 9 47.4 9/19
Hi Richard....thanks for your response. When I set device equal png (goptions device=png;), the calculation of the percentage is correct but the percentage values that I specified for the y axis is not recognized. When I set device equal to actximg, the percentage calculation are different.
I do see the problem now, the ACTXIMG bars do not appear to be to scale.
The percentage values show in the hover text is correct though.
I think the problem is your expectation more so than the Proc.
The vertical axis statement VALUE= option controls the text labels on the major tick marks but DOES NOT DEFINE those tick values. The tick values must by specified in the ORDER= option. The ACTXIMG major ticks that you are experiencing are not 0 to 100, but you are labeling them so and therein lies the confusion.
Change the AXIS statement to
Axis1 style=1 width=1 minor=none label=(height=9pt font="arial/bold" angle=90 "Percent") value=(height=9pt font="arial" "0%" "10%" "20%" "30%" "40%" "50%" "60%" "70%" "80%" "90%" "100%" )
order = 0 to 100 by 10 /* <---- need this */ ;
Hi Richard....I ran the program and that did the trick....thanks for your help...really appreciate it !!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.