BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PierreYvesILY
Pyrite | Level 9

 

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?

1 ACCEPTED SOLUTION

Accepted Solutions
hollandnumerics
Pyrite | Level 9

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;

sizing_PIE.png

Enjoy!..............Phil

Philip R Holland
Holland Numerics: Blog and Forums
http://blog.hollandnumerics.org.uk

View solution in original post

5 REPLIES 5
hollandnumerics
Pyrite | Level 9
PierreYvesILY,
Please could you post a copy of the Beispiel, or a similar, data set so we can test your code?
Philip R Holland
Holland Numerics: Blog and Forums
http://blog.hollandnumerics.org.uk
PierreYvesILY
Pyrite | Level 9

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

hollandnumerics
Pyrite | Level 9

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;

sizing_PIE.png

Enjoy!..............Phil

Philip R Holland
Holland Numerics: Blog and Forums
http://blog.hollandnumerics.org.uk
PierreYvesILY
Pyrite | Level 9

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

 

 

 

 

PierreYvesILY
Pyrite | Level 9

It worked after another step to clean my data in the dataset.

 

Thanks a lot,

Regards,

PY

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 771 views
  • 2 likes
  • 2 in conversation