Hi everyone,
I need to visualise some survey data using a donut chart in PROC GCHART. Because some adjacent pie slices are very small, their percentages and labels overlap. See below (chart generated using sample data):
Is there a way to display the slice percentage on the same line as the slice label instead of after a line break? If yes, can someone provide me with a snippet of code that achieves this? I don't think it's possible within PROC GCHART, but I've heard PROC TEMPLATE or the graphics editor might help (I'm a novice so I can't figure out either). I'm using SAS 8.3.
Alternative solutions I've considered and discarded:
Here's the sample data I used to generate the chart:
data survey;
input name $ q1 & $100.;
datalines;
John Very positive
Cathy Very positive
Phil Very positive
Jason Very positive
Darryl Very positive
Gary Very positive
Courtney Very positive
Andrea Very positive
Dave Very positive
Andy Very positive
Will Very positive
Zach Very positive
Isla Very positive
Florence Very positive
Henry Very positive
Mo Very positive
Evie Very Positive
Nigel Positive
Linda Positive
Anna Positive
Luke Positive
Arlo Positive
Archie Positive
Wendy Positive
Meghan Positive
Jack Positive
Lucy Positive
Theo Positive
Dylan Positive
Grace Positive
Stella Positive
Eva Positive
Nora Positive
Camilla Positive
Violet Positive
Jude Positive
Harry Positive
Louis Neither positive nor negative
Joe Neither positive nor negative
Leo Neither positive nor negative
Janet Neither positive nor negative
Debbie Neither positive nor negative
Alex Neither positive nor negative
Daniel Neither positive nor negative
Nina Neither positive nor negative
Gabe Neither positive nor negative
Oliver Neither positive nor negative
Anthony Neither positive nor negative
Chris Neither positive nor negative
Evan Neither positive nor negative
Adam Neither positive nor negative
Max Neither positive nor negative
Sophia Negative
Mia Negative
Abigail Negative
Caroline Negative
Shane Negative
Chloe Negative
Clint Negative
Lizzie Negative
Sarah Negative
Nick Negative
Amelia Negative
Ava Negative
Hazel Negative
Ivy Negative
Olive Negative
Rose Negative
George Negative
Arthur Negative
Ben Negative
Finn Negative
Elliot Negative
Sam Negative
Josh Negative
Kai Negative
Jacob Negative
Hugo Negative
Mason Negative
Mike Negative
Liam Negative
Vanessa Very negative
Fred Prefer not to say
;
data survey;
input name $ q1 & $100.;
datalines;
John Very positive
Cathy Very positive
Phil Very positive
Jason Very positive
Darryl Very positive
Gary Very positive
Courtney Very positive
Andrea Very positive
Dave Very positive
Andy Very positive
Will Very positive
Zach Very positive
Isla Very positive
Florence Very positive
Henry Very positive
Mo Very positive
Evie Very Positive
Nigel Positive
Linda Positive
Anna Positive
Luke Positive
Arlo Positive
Archie Positive
Wendy Positive
Meghan Positive
Jack Positive
Lucy Positive
Theo Positive
Dylan Positive
Grace Positive
Stella Positive
Eva Positive
Nora Positive
Camilla Positive
Violet Positive
Jude Positive
Harry Positive
Louis Neither positive nor negative
Joe Neither positive nor negative
Leo Neither positive nor negative
Janet Neither positive nor negative
Debbie Neither positive nor negative
Alex Neither positive nor negative
Daniel Neither positive nor negative
Nina Neither positive nor negative
Gabe Neither positive nor negative
Oliver Neither positive nor negative
Anthony Neither positive nor negative
Chris Neither positive nor negative
Evan Neither positive nor negative
Adam Neither positive nor negative
Max Neither positive nor negative
Sophia Negative
Mia Negative
Abigail Negative
Caroline Negative
Shane Negative
Chloe Negative
Clint Negative
Lizzie Negative
Sarah Negative
Nick Negative
Amelia Negative
Ava Negative
Hazel Negative
Ivy Negative
Olive Negative
Rose Negative
George Negative
Arthur Negative
Ben Negative
Finn Negative
Elliot Negative
Sam Negative
Josh Negative
Kai Negative
Jacob Negative
Hugo Negative
Mason Negative
Mike Negative
Liam Negative
Vanessa Very negative
Fred Prefer not to say
;
proc freq data=survey noprint order=freq;
table q1/out=freq1 list;
run;
data freq1;
set freq1;
datalabel=catx(' ',q1,cats(put(percent,8.2),'%'));
run;
%macro circular_plot(dataset_in=,id=);
data temp;
set &dataset_in.;
id+1;id=1000*&id.+id;
pi=PERCENT*0.01*2*constant('pi');
cum_pi+pi;
lag_cum_pi=lag(cum_pi);
if _n_=1 then lag_cum_pi=0;
run;
data plot;
set temp;
/*for a Polygon*/
do _pi=lag_cum_pi to cum_pi by 0.001;
x=&id.*cos(_pi);y=&id.*sin(_pi);output;
end;
x=&id.*cos(_pi);y=&id.*sin(_pi);output;
do _pi=cum_pi to lag_cum_pi by -0.001;
x=%sysevalf(&id.+0.5)*cos(_pi);y=%sysevalf(&id.+0.5)*sin(_pi);output;
end;
x=%sysevalf(&id.+0.5)*cos(_pi);y=%sysevalf(&id.+0.5)*sin(_pi);output;
keep x y id ;
run;
%CENTROID (plot, sgplot, id)
data want;
merge plot sgplot(rename=(x=centroid_x y=centroid_y)) temp(keep=id datalabel) ;
by id;
output;
call missing(of _all_);
run;
proc append base=final_want data=want force;run;
%mend;
proc delete data=final_want;run;
%circular_plot(dataset_in=freq1,id=1)
ods graphics/ANTIALIASMAX=1000000 ;
proc sgplot data=final_want aspect=1 noautolegend noborder;
polygon x=x y=y id=id/fill outline lineattrs=(color=white thickness=2) group=id ;
scatter x=centroid_x y=centroid_y/markerchar=datalabel markercharattrs=(size=10) labelstrip;
xaxis offsetmin=0.1 offsetmax=0.1 display=none ;
yaxis offsetmin=0.1 offsetmax=0.1 display=none ;
run;
@GraphGuy maybe knew how to do it with PROC GCHART.
Could you provide the code you used to produce your gchart pie chart?
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.