Here is some general info about how I created the sas/graph Treemaps
found in this collection of examples...

---

Creating the 'Map'

SAS has had a java version of this kind of chart for quite some time.
But it was designed to be part of the ITRM Solution, and did not 
have an interface for general/easy use from a sas job, and didn't
allow much flexibility about how the map would look, or how the
colors were handled.  

Therefore, I wrote some macros that could take your sas data set,
and create a sas/graph map data set (suitable for use by gmap),
with the size of the boxes controlled by the numeric variable 
you specify.  The code for this macro is in the treemap_inc.sas
file in this directory, and this file gets %include'd in all 
the examples. 

The algorithm is basically brute-force, and recursion.
I take all the data, and sort it, and split it in approx half,
and give each half an amount of treemap area that's proportional
to the sum of the variable you specify.  Then for each 'half'
of the data, I recursively call the macro again, and so on,
until I only have 1 record - when I get down to 1 record, I
go ahead and output the x/y coordinates for that rectangle
of the treemap sas/graph map data set.

As I'm going down through my levels of recursion, I pass the 
data from one level of recursion down to the next by means of
temporary sas data sets -- this is inefficient, and the overhead
adds up when you have a *lot* of rectangles in your treemap.
As a rule of thumb, if you have over 100 rectangles, it's going
to take a noticeable amount of time (if you have several hundred
rectangles in your Treemap, it could take many minutes to run).
It runs pretty quickly if there are under 50 rectangles.

Depending on how you call this macro, you can generate either
a single-level Treemap, or a 2-level Treemap (ie, a Treemap
with subgrouping).  

Once you have the sas/graph map data set of the rectangles, 
you can use 'proc gmap' to draw the map, and shade the rectangles
based on any numeric (or character) variable in your data (just
like you can with geographical maps).

---

Annotating labels and outlines on the map:

Since gmap doesn't have a way to automatically label the areas,
I have created two macros - one creates a sas/graph 'annotate' 
data set containing a label for each rectangle in a single-level
Treemap with no subgrouping (treeanno2_inc.sas)
and the other creates annotate labels for the higher-level grouping
(but not the individual rectangles) as well as a heavy line/border 
around the higher-level grouping  (treeanno_inc.sas).

Back to Samples Index