SAS: How to get a Pie Chart to display the MEAN of a specific column?

Viewed 90

I have created a simple pie chart, but I want the pie chart to display the MEAN (average) of a specific column, which is the "PRICE" attribute from my dataset. My dataset has two attributes - PRODUCT and PRICE.

Below, shows my SAS code used to create the pie chart - but I need some help on how to get the pie chart to display the MEAN for my "PRICE" attribute.

Thanks - any help is much appreciated.

PROC TEMPLATE;
    
    DEFINE STATGRAPH MyPieChart;
    BEGINGRAPH;
    ENTRYTITLE 'AVERAGE PRICE OF PRODUCTS';
    LAYOUT REGION; 
    PIECHART CATEGORY=PRODUCTS RESPONSE=PRICE; // I THINK THE CODE NEEDS CHANGING HERE?
    
    
    ENDLAYOUT;
    ENDGRAPH;
    
END;
RUN;

PROC SGRENDER TEMPLATE=MyPieChart DATA=WORK.IMPORT;
RUN;
1 Answers

Add option / STAT=MEAN.

Lots more info in the Graphics Template Language (GTL) PIECHART statement options documentation.

Example:

data have; input 
products $ price; datalines;
A 1
A 2 
A 3
B 11
B 12
B 13
C 5
C 7
C 8
C 10
;

ods html file = 'pie.html';

PROC TEMPLATE;
    
    DEFINE STATGRAPH MyPieChart;
    BEGINGRAPH;
    ENTRYTITLE 'AVERAGE PRICE OF PRODUCTS';
    LAYOUT REGION; 

    PIECHART 
      CATEGORY=PRODUCTS 
      RESPONSE=PRICE
      /
      STAT=MEAN
    ;
    ENDLAYOUT;
    ENDGRAPH;
    
END;
RUN;

PROC SGRENDER TEMPLATE=MyPieChart DATA=WORK.HAVE;
RUN;

ods html close;

enter image description here

Related