If you are asking yourself, at this point, “what is Graph Template Language, I have never heard of it ?” this might be a good place to start…..
A few years ago, on a bit of whim, I bought a copy of Getting Started with the Graph Template Language in SAS® by Sanjay Matange (ISBN: 9781612907123)
and promised myself that I would learn what this Graph Template Language (GTL) was, and what it might do for me within SAS.
Time went by, as it does, and I promised myself that I really would get down to it, just as soon as I had some spare time…………
Eventually, like a lot of people, 2020 offered me that spare time. I started working through the book and enjoyed putting together the PROC TEMPLATE steps displayed in the book and trying them out with the supplied datasets through PROC SGRENDER.
Now I will have to tell you, up front, and before you get too excited, this book is now out of print, but I notice there are copies lurking around on various book sites or on colleague's bookshelves.
The book is a truly excellent introduction to the Graph Template Language, I now know far more than I ever wanted to know !
Like all good SAS books there was plenty of SAS code and diagrams displaying the relevant output.
However, due to the feature rich nature of PROC TEMPLATE and the constraints of a small format book, I really needed to re-format the code in my own way so that I could see what was going on more easily in order to explain GTL to myself and others. Additionally, I wanted to play about with the sample code in the book to check my understanding. As I come from an era of de-bugging code where I would study a program listing printed on lineflow paper, with a pencil in one hand and a ruler in the other, my preferred code layout tends to be vertical rather than trying to fit loads of stuff all on one line. Not everyone may agree with this technique.
As a result, I ended up keying in all of the examples contained in the book into the attached single SAS program, using my own way of laying out code. I also tried to finally come to grips with some of the bits about the Output Delivery System (ODS) that I had managed to run away from over the years.
As this was a LOT of work, I thought it might be nice to share it with the SAS Community so that others could focus on the Graph Template Language rather than typing in the code.
Consequently I have attached the single SAS program for anyone to use, but, with the following caveat:
This version of the code is offered free-of-charge with absolutely no warranties, you use it at your own risk. Where the code deviates from that shown in the book, it is usually to highlight something that I thought was useful, to myself, as I was working through the original code.
ANY MISTAKES ARE MY OWN.
This code was tested on SAS 9.4 Maintenance Release 6 on SAS Enterprise Guide 8.3 Update 1 on Microsoft Windows.
The SAS code to generate the sample datasets used by several of the examples can be downloaded from:
A Quick Note about storing Templates in Item Stores
I will freely admit when I started down this path, I had trouble getting my head around Item Stores, especially as things would work but I did not know why. As a result, I almost always create practice code like this, with a statement to force Templates into a specific, temporary Item Store, using these statements somewhere at the top of my job to confirm where SAS will be storing my Templates:
ODS PATH(PREPEND) WORK.Daves_Custom_Templates1(UPDATE); ODS PATH SHOW;
Then, during each PROC TEMPLATE, I have added an explicit instruction as to what the name of the Item Store will be that is used to store the template. The following example creates a Statgraph item, the template, called Fig_8_4_4, in the Daves_Custom_Templates1 item store which is stored in the WORK library:
Define StatGraph Fig_8_4_4 / STORE=WORK.Daves_Custom_Templates1;
A Quick Note about ODS statements:
I constructed this piece of code so that individual PROC TEMPLATE/PROC SGRENDER examples could be run without having to run all of the code.
In the book, Sanjay uses the ODS LISTING destination throughout most of the book. I have added a pair of ODS statements immediately preceding PROC SGRENDER step, as follows:
ODS LISTING GPATH="&GraphicsPath"; ODS GRAPHICS / IMAGENAME="Fig_8_4_4";
When I run this code in SAS Enterprise Guide, I turn OFF all ODS destinations like this:
….…and let ODS statements in the code do the heavy lifting. Once more, feel free to do your own thing.
I hope that you get to learn some new stuff about the Graph Template Language by using the attached code along with Sanjay's book and his descriptions about what is going on.
Cheers and Good Luck,
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.