- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 09-19-2010 02:34 PM
(2668 views)
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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".
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".
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hint:
Professor (and student) should read "Save the Pies for Dessert" by S. Few
Professor (and student) should read "Save the Pies for Dessert" by S. Few
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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...
http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#annodict-cntl2txt...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
// 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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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...)
The gslide should make it easy to have titles.
(or, you could annotate some title text...)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
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;