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.
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.
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
This gives me a data set looking like this
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.
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.
A nicely chosen data network example for the jubilee weekend!
Thanks for this, ChrisBrooks!
Does anyone have a program to interpret GEDCOM family tree files in SAS?
Hi @NinaL I'd never heard of GEDCOM before but Wikipedia tells me it's a plain text file consisting of different record types holding genealogical data. I can't find anything which will convert them directly to SAS format but these are the type of files I used to work with a lot when I started on COBOL many years ago so it should be possible to write your own parser without too much difficulty providing you work out a good plan first (I see for example that an individual can have muliple birth dates shown where there is some doubt - you'd have to decide how you handle that).
It also appears that there are some freely available converters to e.g. Excel or JSON. It might be easier to first convert GEDCOM to one of them, import that file into SAS and then make whatever changes to the SAS file that you want, just google GEDCOM to whatever format you want to try.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.