Data visualization with SAS programming

using proc gchart for pie charts

Reply
Contributor
Posts: 57

using proc gchart for pie charts

[ Edited ]

Hello ,

Is there any way to roundup the percentage values in a pie chart. I don't want any decimal points to be displayed. Also I want the title bold and will like to display all slices even those below 0%. I dont want them to be labelled other.

I used other =0 but still have not the appropriate results. I will appreciate any help. Thanks

Super User
Super User
Posts: 9,193

Re: using proc gchart for pie charts

You should be able to apply a format directly to it, for example:

http://support.sas.com/kb/24/877.html

Contributor
Posts: 57

Re: using proc gchart for pie charts

[ Edited ]

proc format is not changing the decimal pointpie.jpg  a similar chart of what I have. I do not want any decimals

goptions  border htitle=12pt htext=10pt;


pattern1 color=red;
pattern2 color=green;
pattern3 color=orange;
pattern4 color=purple;


proc format;
   percent pctfmt (round) 0-high='000%';
run;

/* Define a legend */

legend1 label=("my pie")

position=(bottom )

offset=(4,)

across=1

value=(color=black)

shape=bar(4,1.5);



proc gchart data=pie;

title "my pie chart";

pie cars /sumvar= percent

clockwise value=none

legend=legend1

percent=inside

radius=25

noheading;

 format percent pctfmt.;   


run;

 please help I want only intergers without any decimal places

SAS Employee
Posts: 1,024

Re: using proc gchart for pie charts

I don't think your user-defined-format is running correctly.

 

proc format;
   percent pctfmt (round) 0-high='000%';
run;

 

When I try to run it, I get the following error:

 

 

237 proc format;
238 percent pctfmt (round) 0-high='000%';
-------
180
ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: The previous statement has been deleted.
239 run;

SAS Employee
Posts: 1,024

Re: using proc gchart for pie charts

Posted in reply to RobertAllison_SAS

If you were letting Gchart calculate the percent values, I don't think you can control the format (number of decimal places).

But since it appears you're pre-calculating the values of the percent variable, you should be able to control the number of decimal places with a format statement. Rather than writing your own user-defined-format, I would recommend just using the sas-supplied percent format.

 

Here's some code that shows letting Gchart calculate the percent (where you can't control the format), and then pre-calculating the percent value (where you can control it with SAS' percent format):


title "Using automatically-calculated percent";
title2 "(can't control format)";
proc gchart data=shoes_summarized;
pie region / type=sum sumvar=sales percent=outside value=none noheading other=0;
run;

 

pie1.png

 

proc sql noprint;
create table shoes_summarized as
select unique region, sum(sales) as sales
from sashelp.shoes
group by region;
create table shoes_summarized as
select unique region, sales, sum(sales) as total_sales
from shoes_summarized;
quit; run;
data shoes_summarized; set shoes_summarized;
percent=sales/total_sales;
run;


title "Using manually pre-calculated percent";
title2 "(can control format)";
proc gchart data=shoes_summarized;
format percent percent7.0;
pie region / type=sum sumvar=percent value=outside slice=none noheading other=0;
run;

 

 

pie2.png

 

Contributor
Posts: 57

Re: using proc gchart for pie charts

Posted in reply to RobertAllison_SAS

Okay thanks a lot, I will try your suggetions and leave a feedback.

I probably can't control this because gchart is calculating the percent for me.

Thanks for the idea.

Contributor
Posts: 57

Re: using proc gchart for pie charts

[ Edited ]

Thanks a lot  RobertAllison_S, your suggested method did work. It looks very nice

Ask a Question
Discussion stats
  • 6 replies
  • 404 views
  • 0 likes
  • 3 in conversation