The gchart Procedure. The gchart Procedure is used to create bar charts of various types (it can also create pie charts. It’s most basic form would look something like this: proc gchart data =save.padgett; vbar plantht; run ; quit ;. The gchart Procedure.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
procgchartdata=save.padgett;
vbar plantht;
run;
quit;
This is kind of like
a histogram, except
for the spacing
This value of 75
corresponds to a
class ranging from
67.5 to 82.5
(with a frequency
of about 60)
Sets the number of midpoints
procgchartdata=save.padgett;
vbar plantht/space=0type=percent levels=9;
run;
quit;
Controls spacing between bars
Changes the statistic from frequency
to percent
This is a histogram
procgchartdata=save.padgett;
vbar plantht/space=0type=percent
midpoints=0255075100125150;
run;
quit;
The chart will be constructed
with these 7 values as class
midpoints
procformat;
value classes
low-<30='<30'
30-<60=’30-60'
60-<90=’60-90'
90-<120=’90-120'
120-high='>120'
;
run;
procgchartdata=save.padgett;
vbar plantht/space=0type=percent;
format plantht classes.;
run;
quit;
SAS establishes
the midpoints first
then applies the format
Oops
procgchartdata=save.padgett;
vbar plantht/discretespace=0type=percent;
format plantht classes.;
run;
quit;
Discrete establishes each distinct
value of the midpoint variable as
a midpoint on the graph. If the
variable is formatted, the formatted
values are used for the construction.
If you use discrete with
a numeric variable you
should:
1. Be sure it has only a
few distinct values.
or
2. Use a format to make
categories for it.
Bar width determines
the space available for
writing midpoint values
procgchartdata=save.plantht;
vbar plantht/discretespace=0type=percent width=12;
format plantht classes.;
run;
quit;
Sets bar width
proc format;
value $pol_type 'CO' = 'Carbon Monoxide' 'LEAD' = 'Lead' 'O3' = 'Ozone'
'SO2' = 'Sulfur Diox.';
run;
procgchartdata=save.projects;
hbar pol_type/discretetype=percent;
format pol_type pol_type.;
run;
quit;
Besides the orientation
of the bars, horizontal bar
charts differ in that they
produce a set of summary
statistics by default.
You can suppress this with
the nostats option.
procgchartdata=save.projects;
hbar pol_type/discretesumvar=jobtotal type=meannostats;
format pol_type $pol_type.;
run;
quit;
Mean total cost is
now summarized for
each pollution type.
Note: Only two types of statistics
are available with summary variables,
the sum (which is the default) and
the mean
axisnoptions;
where n is an integer between 1 and 99.
procgchartdata=save.projects;
hbar pol_type/discretesumvar=jobtotal type=meannostats maxis=axis1 raxis=axis2;
format pol_type $pol_type.;
axis1label=(c=blue h=1.5f=swissb ’Type of Pollution Project');
axis2order=(0 to 100000 by 20000) minor=(n=1) value=(h=1.25f=swissb)
label=(f=swissb c=red h=1.5'Mean Job Cost in Dollars');
run;
quit;
Assign axis statements
to each chart axis
Choose options/modifications
for specified axis
sets axis color
sets axis width
controls appearance of axis values, options are similar to those for label.
sets axis starting and ending points and increment
patternid=midpoint
gives each bar its own
“pattern” or color
goptionscolors=(blue red yellow cyan orange);
procgchartdata=save.projects;
hbar pol_type/discretesumvar=jobtotal type=meannostats
maxis=axis1 raxis=axis2 patternid=midpoint;
format pol_type $pol_type.;
axis1label=(c=blue h=1.5f=swissb ’Type of Pollution Project');
axis2order=(0 to 100000 by 20000)
minor=(n=1) value=(h=1.25f=swissb) label=(f=swissb c=red h=1.5’Mean Total Project Cost');
run;
quit;
This color becomes
the default axis and
text color
L, R and X
correspond
to left-leaning,
right-leaning
and crossed
lines. The
number
controls the
thickness
Add these pattern statements to your previous code to get the above bar graph:
pattern c=black v=L1; pattern c=black v=R1;
pattern c=black v=X1; pattern c=black v=L5;
pattern c=black v=R5;
procgchartdata=save.padgett;
hbar marsh/group=flower discretesumvar=plantht type=meannostats maxis=axis1 raxis=axis2 gaxis=axis3 patternid=midpoint;
format marsh marsh. flower flower.;
axis1label=(c=blue h=1.5f=swissb ’Marsh');
axis2order=(0 to 120 by 20) minor=(n=1) value=(h=1.25f=swissb)
label=(f=swissb c=red h=1.5'Mean Plant Height in Centimeters');
axis3label=(c=green h=1.5f=swissb ’Flowering');
run;
quit;
Sets up a “grouping” variable—bars for the
full set of midpoints are constructed for each
value of the group variable
We can modify the
group axis as well
Subgroup creates
stacked bars across levels
of a variable. (Not
appropriate for means)
proc gchart data=save.padgett;
hbar marsh/group=flower discrete type=percent nostats maxis=axis1 raxis= axis2 gaxis=axis3 patternid=subgroup subgroup=form legend=legend1;
format marsh $marsh. flower $flower.;
axis1 label=(c=blue h=1.5 f=swissb 'Marsh');
axis2 order=(0 to 50 by 10) minor=(n=1)
value=(h=1.25 f=swissb)
label=(f=swissb c=red h=1.5 );
axis3 label=(c=green h=1.5 f=swissb 'Flowering');
legend1 across=1 label=(c=blue 'Form of Plant') frame cshadow=gray position=(top right) mode=share;