BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi Guys,

Sorry for another pretty newbie post but this situation really stumps me.

I was given data and asked to create relative frequency charts, which I did as you can see from the code.

However, I was also asked to create a Pie chart in which I would have to display the relative frequency (which is percent=inside, not a problem) as well as the average age given a one of the variables (sex, marital status, country, size type) and the standard deviation of the ages.

Basically, the pie charts I have now show what my professor wants but I would also need to show another variable, age, and its mean and standard deviation. I've been looking through the help file for hours and am stumped. Any help would be met with much joy and great appreciation!


data Preference;
input Sex $ MaritalStatus$ Age Country $ Size $ Type $;
datalines;
Male Married 34 American Large Family
Male Single 36 Japanese Small Sporty
Male Married 23 Japanese Small Family
Male Single 29 American Large Family
Male Married 39 American Medium Family
Male Single 34 Japanese Medium Family
Female Married 42 American Large Family
Female Married 40 European Medium Family
Male Married 28 American Medium Sporty
Female Married 26 American Medium Family
Female Married 26 European Small Sporty
Male Single 26 European Medium Sporty
Female Married 37 American Medium Sporty
Male Single 25 Japanese Small Sporty
Female Single 27 Japanese Medium Family
Male Married 41 American Large Family
Male Single 35 American Small Sporty
Male Single 23 American Medium Work
Male Married 28 Japanese Small Family
Male Married 38 European Medium Family
;
run;

proc means data= Preference n mean std;
var Age;
class Sex;
title Descriptive Statistics for Sex based on Age;
run;

proc means data= Preference n mean std;
var Age;
class MaritalStatus;
title Descriptive Statistics for Marital Status based on Age;
run;

proc means data= Preference n mean std;
var Age;
class Country;
title Descriptive Statistics for Country based on Age;
run;

proc means data= Preference n mean std;
var Age;
class Size;
title Descriptive Statistics for Size based on Age;
run;

proc means data= Preference n mean std;
var Age;
class Type;
title Descriptive Statistics for Type of Car based on Age;
run;

proc print noobs data= Preference;
var Sex MaritalStatus Age Country Size Type;
title Car Preferences for 20 Observations;

run;

proc freq data=Preference ;
tables Sex MaritalStatus Country Size Type/ nocum;
title Frequency Tables for Car Preference Observations;

run;

proc gchart data= Preference;
pie Sex / Percent=inside Discrete Value=inside noheading;
title Sex of the Observations;

run;

proc gchart data= Preference;
pie MaritalStatus / Percent=inside Discrete Value=inside noheading;
title MaritalStatus of the Observations;

run;

proc gchart data= Preference;
pie Country / Percent=inside Discrete Value=inside noheading;
title Country of origin for the Observations;

run;

proc gchart data= Preference;
pie Size / Percent=inside Discrete Value=inside noheading;
title Size of the Observations;

run;

proc gchart data= Preference;
pie Type / Percent=inside Discrete Value=inside noheading;
title Type of car for the Observations;
run;


Thanks much again,
Henry
9 REPLIES 9
GraphGuy
Meteorite | Level 14
One question first...

You mention "professor". Is this a school assignment, or is this some (non-graded) research you're working on?

The reason I ask is that if it's a graded assignment, responders should lean towards only giving "hints" and "tips".
Bill
Quartz | Level 8
Hint:

Professor (and student) should read "Save the Pies for Dessert" by S. Few
deleted_user
Not applicable
It is a good suggestion (to read the article), as I think the assignment suggests pie charts should have more information than is typically effective. I think the big question needing to be answered here, however, is whether or not the gchart procedure allows for modification of the slice labels in terms of adding grouped data (such as the average age in this case). I am also a student in this class and I have yet to meet another student (we are permitted to work together) to find a way to do this. It seems quite simple to generate the frequency tables and it is also quite simple to create a pie chart. If someone can please suggest a command or option to start with in altering the pie chart to accomodate additional data, it would only serve to aid us in making the most out of SAS.
GraphGuy
Meteorite | Level 14
Here's one way to put any kind of text you want for the slices of a pie chart (possibly a little more than you'd want, since it uses annotate to draw the pie, rather than proc gchart)...

http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#annodict-cntl2txt...
deleted_user
Not applicable
Thank you for your helpful suggestion. I had tried using annotate, but I didn't realize that there was this other way to draw the pie chart. I was able to use this to create a 2 slice pie chart using the following code.

It would be nice if there was a description of how to draw and label multiple slices on the documentation you referenced (like an example of a whole pie chart with 2 or 3 slices each labeled independently). If such a thing doesn't exist, then I suppose I will post mine when I'm done.
deleted_user
Not applicable
// Forgot to add the code. I'm still tweaking the locations.


data pielabel;
retain xsys ysys "3";
length function style $ 8;
function="pie"; angle=90; size=10; x=30; y=60;
style="P5N15"; rotate=105; output;
function="piexy"; angle=105; size=1.1; output;
function="cntl2txt"; output;
function="label"; text="Slice 1"; angle=0; rotate=0;
position="4"; style="swissb"; size=1; x=13; y=75;
output;
function="pie"; angle=195; size=10; x=30; y=60;
style="P2N30"; rotate=255; output;
function="piexy"; angle=0; size=1.1; output;
function="cntl2txt"; output;
function="label"; text="Slice 2"; angle=0; rotate=0;
position="6"; style="swissb"; size=1; x=.; y=.;
output;
text="Info2"; angle=0; rotate=0;
position="9"; style="swissb"; size=1; x=50; y=.;
output;
run;

title "2 slice labeled pie chart";

proc ganno anno=pielabel;
run;
quit;

updated the stacking text label


Message was edited by: zoomweb Message was edited by: zoomweb
deleted_user
Not applicable
The title isn't displaying, any suggestions?

Also, as you can see in the code, I eneded up having to manually give x and y values for the most part obviating the need for piexy. When I tried using piexy, the labels seemed to end up in the wrong place, so I gave up on that for now. I will go back to this and fix it up later.
GraphGuy
Meteorite | Level 14
Maybe try annotating onto a "proc gslide", rather than using "proc ganno".

The gslide should make it easy to have titles.
(or, you could annotate some title text...)
deleted_user
Not applicable
gslide worked nicely, thank you..

data pielabel;
retain xsys ysys "3";
length function style $ 8;
function="pie"; angle=90; size=10; x=30; y=60;
style="P5N15"; rotate=108; output;
function="label"; text="Slice 1"; angle=0; rotate=0;
position="4"; style="swissb"; size=1; x=10; y=75;
output;
function="pie"; angle=198; size=10; x=30; y=60;
style="P2N30"; rotate=252; output;
function="piexy"; angle=0; size=1.1; output;
function="cntl2txt"; output;
function="label"; text="Slice 2"; angle=0; rotate=0;
position="6"; style="swissb"; size=1; x=.; y=.;
output;
text="Info2"; angle=0; rotate=0;
position="9"; style="swissb"; size=1; x=50; y=.;
output;
run;

title "2 slice labeled pie chart";

proc gslide anno=pielabel;
run;
quit;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1412 views
  • 0 likes
  • 3 in conversation