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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.