Hello,
I want o create a pie chart with data structured as the folloing:
data Beispiel(label='Beispiel');
input Structure:$35. Month:2. Anz:5.; /* Anz is a numeric value, actually */
datalines;
Nord 1 250
South 1 305
Center 1 444
East 1 140
West 1 456
Nord 2 210
South 2 175
Center 1 413
East 2 199
West 2 302
Nord 3 150
South 3 405
Center 3 124
East 3 140
West 3 456
Nord 4 105
South 4 375
Center 4 145
East 4 240
West 4 159
;
run;
I wrote:
PROC TEMPLATE;
DEFINE STATGRAPH pie;
BEGINGRAPH;
LAYOUT REGION;
PIECHART CATEGORY = Anz / group=monat
DATALABELLOCATION = OUTSIDE
DATALABELCONTENT = ALL
CATEGORYDIRECTION = CLOCKWISE
START = 180 NAME = 'pie';
DISCRETELEGEND 'pie' /
TITLE = 'Anzahl der Anträge';
ENDLAYOUT;
ENDGRAPH;
END;
RUN;
proc sgrender data=Beispiel template = pie; run;
it gives stupid results (calculation the number of structures for each month and classified by Anz value). The reverse (variable = Structure instéad of Anz).
How should I proceed to get a pie chart where the value of Anz gives the part of each structure for each month?
PY, I think you have missed out the response= part of the template. If you try using my PIE2 template instead, then, using your supplied data set code, your pie chart will look like the one below:
PROC TEMPLATE; DEFINE STATGRAPH pie2; BEGINGRAPH; LAYOUT REGION; PIECHART CATEGORY = structure response = anz / group=month stat = sum DATALABELLOCATION = OUTSIDE DATALABELCONTENT = ALL CATEGORYDIRECTION = CLOCKWISE START = 180 NAME = 'pie'; DISCRETELEGEND 'pie' / TITLE = 'Anzahl der Anträge'; ENDLAYOUT; ENDGRAPH; END; RUN; proc sgrender data=Beispiel template = pie2; run;
Enjoy!..............Phil
hallo Philipp,
thanks for your interest.
The Beispiel Data is the following, and should be directly copied into your SAS session without any pb:
data Beispiel(label='Beispiel');
input Structure:$35. Month:2. Anz:5.; /* Anz is a numeric value, actually */
datalines;
Nord 1 250
South 1 305
Center 1 444
East 1 140
West 1 456
Nord 2 210
South 2 175
Center 1 413
East 2 199
West 2 302
Nord 3 150
South 3 405
Center 3 124
East 3 140
West 3 456
Nord 4 105
South 4 375
Center 4 145
East 4 240
West 4 159
;
run;
This Dataset is only an exemple, my actual Dataset is a lot bigger, but for code testing purpose I wrote this one extra.
YOu have 5 'Structure' items (Nord, SOuth, Center, East, West)
4 Months from 1 to 4
and a value Anz (=Anzahl) between 0 and 1000 for each Structre + Month.
The desired pie displays in each Pie Sector a Structure for each month, and the size of the Pie sector is given by the Anz value: Anz /(Sum of Anz).
Order of the months as in the group=monat option is perfectly fine.
I hope it helps.
The code I wrote after the DAtaset is giving a result where all sectors are of the same size, not displaying the size accordingly to the Anz /(Sum of Anz).
That's the point I don't resolve myself. Don't know how to, although I checked many pie related tutorials / pages / doc.
Thanks a lot,
have a nice day,
PY
PY, I think you have missed out the response= part of the template. If you try using my PIE2 template instead, then, using your supplied data set code, your pie chart will look like the one below:
PROC TEMPLATE; DEFINE STATGRAPH pie2; BEGINGRAPH; LAYOUT REGION; PIECHART CATEGORY = structure response = anz / group=month stat = sum DATALABELLOCATION = OUTSIDE DATALABELCONTENT = ALL CATEGORYDIRECTION = CLOCKWISE START = 180 NAME = 'pie'; DISCRETELEGEND 'pie' / TITLE = 'Anzahl der Anträge'; ENDLAYOUT; ENDGRAPH; END; RUN; proc sgrender data=Beispiel template = pie2; run;
Enjoy!..............Phil
Thanks a lot Phil,
I will use adapt this code to my actual data and check that it also works.
Your result is actually exactly what I want.
I'll let you know if I encounter further problems with the actual data.
Thank you again,
Regards,
PY
It worked after another step to clean my data in the dataset.
Thanks a lot,
Regards,
PY
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.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.