Click here to see the SAS code shared by all these gas mileage graphs (mpgplot.sas).

Click here to see code used to import the MPG data from the xls spreadsheets.

Click here to see the SAS code (suv).
Click here to see the example (suv).

Click here to see the SAS code (van).
Click here to see the example (van).

Click here to see the SAS code (truck).
Click here to see the example (truck).

Click here to see the SAS code (station wagon).
Click here to see the example (station wagon).


---------------------------------------------------------------

I got all the mpg data (2008-1984) from:
fueleconomy.gov

One of the main problems with this data is that it doesn't tell how
many of each vehicle were sold - therefore, when I plot the data,
a vehicle such as a Ferrari (which maybe only a handful were sold)
that gets 10mpg has the same visual 'weight' in the graphs as a
Camry (which 1000s were sold) that gets 30mpg+.


These are fairly regular sas/graph "proc gplot" scatter plots,
of the form "plot y*x=z", where z is the number of cylinders in 
the car (and controls the color of the plot markers).

I also 'annotate' a diagonal reference line from the bottom/left 
to the top/right - this allows you to easily see if the city mileage
is better than the highway mileage (which is indicative of some of
the new hybrid vehicles).

And finally the "tricky" part... the boxplots.
Since there could be many vehicles represented at the exact same 
x/y location, I wanted a way to visually show a summary of the data that 
takes into account all the obsns - what better way than a boxplot.
But, I wanted to show it on the same graph as the scatter plot.
There's nothing easy/built-in to sas/graph to do that.
Therefore as a work-around, I ran "proc boxplot" and used the 
"outhistory=" option to output the numerical description of the 
boxplot (instead of letting proc boxplot produce graphical output).
I then took the numerical description and created a dataset 
containing the 'annotate' functions/commands to draw what looks
like a boxplot, using these numbers (one in the x-direction, and
one in the y-direction).


Back to Samples Index