Click here to see the SAS code.
Click here to see the example.
---------------------------------------------------------------
I got the data for the table (and the basic idea for the table)
from the following Wikipedia page:
http://en.wikipedia.org/wiki/Blood_type
---
This is not really a 'graph' per say, but I think when you
color-code a table then it has the same visual characteristics
as a graph/chart/map, so I'm including it in these samples.
There are many ways to create tables in SAS...
I used Proc Tabulate to create this one. This proc likes
to have numeric values in the cells, so I used the standard
'binary' 0/1 to represent whether or not each combination
of donor/recipient was compatible. I wanted the 0/1 values
to show up in the table as text n/y (because that's more easily
human-readable), therefore I used a user-defined-format.
I also used a user-defined-format to color the background
of the cells red/green.
Below is a step-by-step description of how I created and
customized the table:
-----
Here's the basic Proc Tabulate. Notice that the axes are
sorted alphabetically, and the values in the cells are
numeric 0/1 (not easily readable by humans):
proc tabulate data=blood_data f=1.0;
class recipient donor;
var numeric_compatible;
table recipient,donor *
( numeric_compatible='' *
sum=''
);
run;
I include options to keep the Recipient & Donor
blood type values in "data order" (rather than the
default alphabetical order), and I center the
Recipient blood types:
proc tabulate data=blood_data f=1.0;
class recipient donor / order=data; <---
classlev recipient/style=[just=c]; <---
var numeric_compatible;
table recipient,donor *
( numeric_compatible='' *
sum=''
);
run;
I use a user-defined format (which I call yn_text)
to make the 0/1 values print in the table as n/y.
The text values is more mnemonic, and easier for
humans to understand. Also, the n/y text will
provide an alternate means of reading the chart,
for those who are red/green color blind.
proc format;
value yn_text
0 = 'n'
1 = 'y';
run;
proc tabulate data=blood_data f=1.0;
class recipient donor / order=data;
classlev recipient/style=[just=c];
var numeric_compatible;
table recipient,donor *
( numeric_compatible='' *
sum='' *
f=yn_text.*{style=[just=c]} <---
);
run;
I also create a user-defined-format (yn_color) to control
the background colors of the cells in the table, making
them red or green, based on the 0/1 values.
proc format;
value yn_color
0 = 'red'
1 = 'cx00ff00';
run;
proc tabulate data=blood_data f=1.0;
class recipient donor / order=data;
classlev recipient/style=[just=c];
var numeric_compatible;
table recipient,donor *
( numeric_compatible='' *
sum='' *
f=yn_text.*{style=[just=c background=yn_color.]} <---
);
run;
Back to Samples Index