BookmarkSubscribeRSS Feed

Comparing similar metrics using SAS Visual Analytics custom graphs

Started ‎10-29-2018 by
Modified ‎10-29-2018 by
Views 2,713

Creating visualizations that compare similar metrics across a categorical variable can be tricky.  The report designer needs to show how the values of the two metrics compare, while also allowing the report consumer view those comparisons within an overall group.  As I have mentioned in my previous post, I'm a big fan if using butterfly charts for this type of visualization.  However, I'm often searching more creative ways to do this type of reporting that might be more useful than butterfly charts. 


The good news is the SAS Graph builder is useful for exactly this task. Using the builder, I was able to create the following report:




Looks cool! 


In the example above I've used the Graph builder to create a chart which displays two metrics within a group.The two metrics I'm comparing are the City Miles Per Gallon (MPG) and Highway MPG.  The builder has also allowed me to add a categorical variable, in which I placed the variable Make (or car manufacturer).


The best part is, by using the graph builder this report is very easy to make.  In this post, I'll show you how.


Step 1: Building the custom graph


Begin by opening the SAS® Graph Builder and dragging a "Schedule Chart" onto the center pane:



 From here click the "Options" menu on the left side of your screen.  Increase the spacing up to 95%.




From the drop down at the top to the "Options" menu, select "X Axis" and UNCHECK the box next to "Axis label":




Next, from the "Elements" menu on the right add TWO "Bubble Plots" onto the center pane:



With these three graph elements in place, all we have to do is adjust the custom graph's roles.


Click the Roles Menu from the right side of your screen. 


Click the dots next to "Shared Role 1" and click "Edit Role":




Change the Role Name to "Category" and press "OK".




Next (still on the "Roles" menu) scroll down to the "Bubble Plot 1" section.  Click the three dots next to "Bubble Plot 1 X" and choose "Create shared role" -> "Schedule Chart 1 Start":




At the next screen change the role name to be "Measure1" and press "OK".




Next (still within the "Bubble Plot 1" section) click the three dots next to the "Bubble Plot 1 Size" and choose "Edit Role":




Change the role name to "Measure 1 Size" and press OK.




The next step is to do the same steps on the roles within the "Bubble Plot 2" section.  However for this section, create the shared role with "Schedule Chart 1 Finish" and rename it "Measure2".  Rename the "Bubble Plot 2 Size" role to "Measure2 Size".


When finished, your roles menu should look like this:




And you're done!  You've created a custom graph that has the proper elements to become the data visualization at the top of this post.  Save your custom graph and give it a name. 


Step 2: Build the report:


For the data in this post, I used data sourced from the SASHELP data set: 'cars'.  I summarized the data by "Make" (or car manufacturer) and sub-setted to cars with a Origin value of "Europe".  I titled the output data set "Cars_By_Make".  The SAS code to do these simple operations is attached to this post.  Import the "CARS_BY_MAKE" on your SAS Visual Analytics instance.


To build the report we will first import the custom graph to a new SAS Visual Analytics report.  Add your new custom graph to your reporting canvas. 


Then fill out the "Roles" for your custom graph as shown below:



The "Make" variable will be the "Category" (or Task) from our Schedule Chart.  MPG City and MPG Highway will be the two metrics we want to compare, respectively.  Since we used bubble plots to create the 'ends' of our 'lines,' we have to assign each of them a value.  We want these values to be the same.  Hence, the data set we are using contains two 'dummy' columns with a value of 1.  These two columns are "Bubble1_Size" and "Bubble2_Size".  These columns are assigned to (you guessed it) the "Measure1 Size" and "Measure2 Size" roles we created.


And that's it!  Add a title to your tab and you're report is complete!




Additionally, I created a custom legend from a text object and placed it under the graph.  I also have adjusted the report-level options to acquire the colors in my report above.  Both of these final report edits are included in the report's JSON file that is attached to this post.


How to make this example work for you

This example was created in SAS Visual Analytics 8.3.  Again, for this post's data, I used data sourced from the SASHELP data set, 'cars,' and did some basic data manipulation to it.  The SAS code that performs this data manipulation is attached to this post.    


The attachments for this post are:

  • The code to create the report-ready data -
  • A JSON file containing the custom graph and Report- Compare_Similar_Metrics.json

Import the data on your SAS Visual Analytics instance.  Import the report via the "Import via GUI" section of these instructions.  



I'm following the instructions but I don't know how to use this file

What is the interfaz to copy this code to? 

thank you!

Hello samisuperss!


Within your Viya platform you can submit this SAS code in the SAS Studio 5.1 programming interface:


Happy coding!

- Mike

Awesome, thank you Mike!!

Version history
Last update:
‎10-29-2018 09:01 AM
Updated by:


Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.


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 Labels
Article Tags