BookmarkSubscribeRSS Feed

Draw Your Family Tree with SAS

Started ‎06-03-2022 by
Modified ‎06-03-2022 by
Views 2,378
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:
 

 

This year the United Kingdom is celebrating the platinum jubilee of the accession to the throne of Queen Elizabeth II.organization-chart-g3c81c3cbf_640.jpg 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

 

  1. 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.
  2. 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.
  3. 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.

 

Family Tree Fig 1.png

 

This gives me a data set looking like this

 

Family Tree DS 1.png

 

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.

 

Family Tree Chart 1.png

 

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.

 

 

 

Comments

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.

Version history
Last update:
‎06-03-2022 02:49 PM
Updated by:

SAS Innovate 2025: Register Now

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!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags