BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASGeek
Obsidian | Level 7

Hello,

I'm trying to create a simple pie chart in SAS to eventually export into Excel as a graph (user request). I'm trying everything I know but I can't get percentages to show and calculate.  Here's what I have

 

/* Step 1: Create the dataset in desired order */
data test;
    input rating $ count;
    datalines;
    Amber 1000
    Green 450
    Red   6445
    ;
run;

 

/* Step 2: Define custom colors in the same order */
pattern1 color=orange; /* Amber */
pattern2 color=green;  /* Green */
pattern3 color=red;    /* Red */

 

/* Step 3: Create the pie chart with percentages */
proc gchart data=test;
    pie rating / sumvar=count
                 type=percent      /* Show percentages */
                 value=inside      /* Place percentages inside slices */
                 other=0
                 noheading
                 legend;
    title "Rating Distribution (Percentages)";
run;
quit;

 

instead of the numbers (1000, 450, 6445) I want it to show 13%, 6%, and 82%.  And since the values can always flip, I want the first to show amber, 2nd to show green, 3rd to show red even if the percentages are 54%, 22%, and 24%. 

 

Would someone help me please?  Google isn't my friend this Friday afternoon. Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Now you could use PROC SGPIE to get pie chart.

title "Regional Sales";
data test;
    input rating $ count;
    datalines;
    Amber 1000
    Green 450
    Red   6445
    ;
run;
proc sgpie data=test;
donut rating / response=count holevalue datalabeldisplay=(percent)
               holelabel="Total Sales" datalabelloc=outside;
run;

Ksharp_0-1762588958574.png

 

 

 

title "Regional Sales";
data test;
    input rating $ count;
    datalines;
    Amber 1000
    Green 450
    Red   6445
    ;
run;
proc sgpie data=test;
pie rating / response=count  datalabeldisplay=(percent)
                datalabelloc=inside;
run;

Ksharp_1-1762589021683.png

 

View solution in original post

2 REPLIES 2
Ksharp
Super User

Now you could use PROC SGPIE to get pie chart.

title "Regional Sales";
data test;
    input rating $ count;
    datalines;
    Amber 1000
    Green 450
    Red   6445
    ;
run;
proc sgpie data=test;
donut rating / response=count holevalue datalabeldisplay=(percent)
               holelabel="Total Sales" datalabelloc=outside;
run;

Ksharp_0-1762588958574.png

 

 

 

title "Regional Sales";
data test;
    input rating $ count;
    datalines;
    Amber 1000
    Green 450
    Red   6445
    ;
run;
proc sgpie data=test;
pie rating / response=count  datalabeldisplay=(percent)
                datalabelloc=inside;
run;

Ksharp_1-1762589021683.png

 

SASGeek
Obsidian | Level 7

That's perfect. Thank you. Really appreciate the help!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 401 views
  • 0 likes
  • 2 in conversation