0

I am working on an analysis of coping mechanisms for a project I am working on. I have each coping mechanism in a different variable and want to make a pie chart to visually represent how many people are using each coping mechanism but I do not know how to do that.

The data looks like this

data test;
input cope_1 cope_2 cope_3 cope_4;
datalines;
0 1 1 0
1 1 0 0
1 0 0 0
0 0 1 1
0 1 0 1 
1 1 1 1
0 0 0 1
1 0 1 1
0 0 1 0
;
run;

I know I can use proc gchart with a pie option to create different pie charts for each coping variable and was able to successfully do that with the below code but I want one pie chart for all 4 variables

proc gchart data=test;
pie cope_1 cope_2 cope_3 cope_4 / other=0
value=none
percent=arrow
slice=arrow
noheading
plabel=(font='Albany AMT/bold' h=1.3);
run;
quit;

Ryan
  • 15
  • 5
  • Pie charts typically add up to 100% where your data allows for multiple responses, it will not add up to 100%. I would recommend a bar chart for this type of data instead. – Reeza Jul 19 '23 at 19:07

1 Answers1

1

I would not recommend a donut/pie chart here. Your total will add up to more individuals than you observed, making the 'slices' incorrect. Instead a bar chart. However, since that was the question asked, please see a response for a donut chart as well as a bar graph below.

data test;
input cope_1 cope_2 cope_3 cope_4;
*added in to support flipping the data;
id = _n_;
datalines;
0 1 1 0
1 1 0 0
1 0 0 0
0 0 1 1
0 1 0 1 
1 1 1 1
0 0 0 1
1 0 1 1
0 0 1 0
;
run;

*flip the data to an easier structure to work with;
proc transpose data=test out=coping;
by id;
run;

*donut chart (change donut to pie for pie chart);
proc sgpie data=coping;
donut  _name_ / response = col1 datalabeldisplay=(response);
run;

*bar graph;
proc sgplot data=coping;
vbar _name_ / response = col1 stat=sum;
xaxis label = 'Coping Response';
yaxis label = '# of individuals';
run;
Quentin
  • 5,960
  • 1
  • 13
  • 21
Reeza
  • 20,510
  • 4
  • 21
  • 38