BookmarkSubscribeRSS Feed
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 REPLY 1
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

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 104 views
  • 0 likes
  • 2 in conversation