BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Golf
Pyrite | Level 9

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 

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

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,

View solution in original post

3 REPLIES 3
ed_sas_member
Meteorite | Level 14

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,

Golf
Pyrite | Level 9
Thank you so much.
ed_sas_member
Meteorite | Level 14
You're welcome @Golf !

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
  • 3 replies
  • 1272 views
  • 1 like
  • 2 in conversation