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,
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.