Hello,
I have one categorical with 5 values: 1, 2, 3, 4, 5. The data is 50 observations.
I'd like to create pie chart showing in frequency by using proc schart as follow:
proc gchart data=softdrink_new;
format X X_value_label.;
pie X / sumvar=X ;
run;
But the result of pie chart show the number which are not frequency of each category and label only on piece of the pie chart.
How can I correct this problem? Moreover, how to show the number in percentage in separate and the same pie chart?
Thank You
Hi @Golf
Would this code meet your needs?
data softdrink_new;
input X @@;
datalines;
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
1 1 1 1 1 1 1 1 4 2 2 2 3 4 5 1 2 3 4 5 1 2 3 4 5
;
run;
proc format;
value X_value_label 1="label1" 2="label2" 3="label3" 4="label4" 5="label5";
run;
/*Only frequencies*/
proc gchart data=softdrink_new;
format X X_value_label.;
pie X / type=freq discrete;
run;
/*Only percents*/
proc gchart data=softdrink_new;
format X X_value_label.;
pie X / type=percent discrete;
run;
/*Frequencies + percent*/
proc gchart data=softdrink_new;
format X X_value_label.;
pie X / percent=outside discrete;
run;
Best,
Hi @Golf
Would this code meet your needs?
data softdrink_new;
input X @@;
datalines;
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
1 1 1 1 1 1 1 1 4 2 2 2 3 4 5 1 2 3 4 5 1 2 3 4 5
;
run;
proc format;
value X_value_label 1="label1" 2="label2" 3="label3" 4="label4" 5="label5";
run;
/*Only frequencies*/
proc gchart data=softdrink_new;
format X X_value_label.;
pie X / type=freq discrete;
run;
/*Only percents*/
proc gchart data=softdrink_new;
format X X_value_label.;
pie X / type=percent discrete;
run;
/*Frequencies + percent*/
proc gchart data=softdrink_new;
format X X_value_label.;
pie X / percent=outside discrete;
run;
Best,
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.