How to create pie chart in SAS?


You can use the PIE statement within PROC GCHART in SAS to create pie charts.

The following examples show how to create four different types of pie charts using the following dataset that contains information about various basketball players:

/*create dataset*/
data my_data;
    input team $ points;
    datalines;
Mavs 14
Mavs 22
Mavs 19
Mavs 31
Heat 14
Heat 25
Warriors 31
Warriors 35
Warriors 36
Jazz 29
;
run;

/*view dataset*/
proc print data=my_data;

Example 1: Create Pie Chart of Frequencies

The following code shows how to create a pie chart that displays the frequency of each unique value in the team column:

proc gchart data=my_data;
    pie team;
run;
quit;

pie chart in SAS

The slices in the pie chart represent the frequency of each unique value in the team column.

Example 2: Create Pie Chart of Sums

The following code shows how to use the SUMVAR statement to create a pie chart that displays the sum of values in the points column for each unique value in the team column:

proc gchart data=my_data;
    pie team / sumvar=points;
run;
quit;

The slices in the pie chart represent the sum of values in the points column for each unique value in the team column.

Example 3: Create Pie Chart with Exploding Slice

The following code shows how to use the EXPLODE statement to create a pie chart that displays the sum of values in the points column for each unique value in the team column with a particular slice “exploded” away from the other slices:

proc gchart data=my_data;
    pie team / sumvar=points explode='Jazz';
run;
quit;

SAS pie chart with exploding slice

Notice that the slice for the Jazz has been exploded away from the other slices.

This can be particularly useful if you want to create a pie chart and make one of the slices stand out for some reason.

Example 4: Create Pie Chart with Custom Labels

The following code shows how to use the PLABEL statement to create a pie chart with labels that have increased font size and a red font color:

proc gchart data=my_data;
    pie team / sumvar=points plabel=(h=1.5 color=red);;
run;
quit;

SAS pie chart with custom labels

Note that the h argument specified the font size and the color argument specified the font color.

The following tutorials explain how to create other charts in SAS:

x