SAS OnDemand for Academics has replaced SAS University Edition as a free e-learning option. Hit the orange button below to start your journey with SAS OnDemand for Academics:
Access Now
This year the United Kingdom is celebrating the platinum jubilee of the accession to the throne of Queen Elizabeth II. A reign of seventy years makes her the longest serving monarch in British history. One thing that is of vital importance in a monarchy is the line of succession, often expressed by a family tree showing the relationship between the monarch and his or her relatives. Of course we all have a family tree and many people take great interest in researching their family and depicting it graphically.
In this episode of Free Data Friday, we will be using data from Wikipedia with Proc Netdraw to draw the family tree of Queen Elizabeth II as an example of how you can use SAS to draw your own family tree or any other hierarchy such as an organisation chart, system menu diagram or object hierarchy.
Get the data
The data is transcribed from Wikipedia. There isn’t a huge amount of data to type in manually, so this isn’t a significant burden.
Get started with SAS OnDemand for Academics
In this 9-minute tutorial, SAS instructor @DomWeatherspoon shows you how to get your data into SAS OnDemand for Academics and other key steps:
Get Started
Getting the data ready
The preparation necessary for drawing the family tree is all done in the creation of the data file to be used. Proc Netdraw is very versatile but for our purposes we need a data set with an activity (parent) variable and a successor (child) variable. Also, we need _x_ and _y_ variables to tell the procedure where to place the nodes and a _pattern variable to control the appearance of the nodes. Here is the code used to create the data set
data royalfamily;
length name $20 successor $20 _x_ 8. _y_ 8. _pattern 8.;
infile datalines delimiter="," missover;
input name $ successor $ _x_ _y_ _pattern;
datalines;
Elizabeth,Charles,1,3,1
Elizabeth,Anne,1,3,2
Elizabeth,Andrew,1,3,2
Elizabeth,Edward,1,3,2
Charles, ,2,3,1
Anne, ,2,6,2
Andrew, ,2,2,2
Edward, ,2,1,2
Charles,William,2,3,1
Charles,Harry,2,3,2
Anne,Peter & Zara,2,6,2
Peter & Zara, ,3,6,2
Andrew,Beatrice & Eugenie,2,2,2
Beatrice & Eugenie, ,3,2,2
Edward,Louise & James,2,1,2
Louise & James, ,3,1,2
William, ,3,3,1
Harry, ,3,5,2
William,George,3,3,1
William,Charlotte,3,3,2
William,Louis,3,3,2
Harry,Archie & Lilibet,3,5,2
Archie & Lilibet, ,4,5,2
George, ,4,3,1
Charlotte, ,4,4,2
Louis, ,4,2,2
;
run;
A few points to note
Because of space constraints on the page/screen I chose to omit spouses from the tree and to only show a single node for children of everyone except the eldest child in the direct line of succession. If you were creating your own family tree you may want to add them in, using separate pages if necessary. You can use an annotate data set if desired.
I decided to show the nodes for those individuals in the direct line of succession in a different color to the others, so I used values 1 and 2 in the _pattern field to do this.
You can see how the data pattern works in the following figure with the parent and child nodes of the direct line numbered (the _x and _y numbers are row and column numbers respectively in the resultant output). Ifyou accidentally omit a required node or specify an illogical hierarchy Proc Netdraw will generate an error.
This gives me a data set looking like this
The results
Drawing the family tree is now straightforward. After two pattern statements and a title statement I simply run Proc Netdraw specifying the activity and successor variables and setting text height.
pattern1 color=red;
pattern2 color=yellow;
title "British Royal Family";
proc netdraw data=royalfamily;
actnet / act=name
succ=(successor)
htext=1.5
;
run;
This generates the following chart.
Now it's your turn!
There is a lot more you can do with Proc Netdraw to design and enhance different types of network diagrams - why not build your own family tree and explore all the possibilities? I’m glad to answer any questions.
Hit the orange button below to see all the Free Data Friday articles.
Free Data Friday
... View more