Hi everyone! 👋
In this article, I’ll guide you on how to streamline SAS Visual Analytics (VA) reports by reducing the number of graphs through the use of a Control object. Often, reports include several graphs that are nearly identical, differing only in the variables they display. Instead of cluttering your report with multiple similar graphs, you can use a single graph with a drop-down list for variable selection, creating a cleaner and more interactive experience.
For example, let’s consider a dataset with 2015 monthly data on energy price components, including both fixed and variable costs for different periods (peak, mid-peak, and off-peak). This dataset, sourced from Kaggle, contains the following six variables:
Instead of creating six separate time series plots to display the average monthly trends of these variables, a single time series plot with a drop-down list allows users to dynamically choose the variable they want to visualize. This approach simplifies your report while enhancing its interactivity.
The video below demonstrates the outcome we’re aiming to achieve:
In the steps below, I’ll guide you through the process of setting this up using a dummy dataset. Let’s dive in!
Note: This procedure is based on this SAS paper. In this article, I provide a detailed explanation of the steps required to implement the same functionality using the latest versions of SAS Viya (the screenshots and procedure are based on release 2024.12).
First, we’ll prepare the data needed to reproduce the result shown in the video.
To adapt this procedure to your use case, adjust the value of the num_vars macro variable in the code to generate distinct values equal to the number of variables you want to use in your dynamic plot.
Additionally, the code converts the price_date variable in the price_data_raw table from character to date format, enabling its use in the Time Series plot.
Now, we’ll create a new report in SAS Visual Analytics and set up the necessary components.
The parameter allows us to create a connection between the Control object and the dynamic variable, which we'll create in the next step.
if(LowerCase('Variable Select Parameter'p) = 'price_mid_peak_fix')
return price_mid_peak_fix
else if(LowerCase('Variable Select Parameter'p) = 'price_mid_peak_var')
return price_mid_peak_var
else if(LowerCase('Variable Select Parameter'p) = 'price_off_peak_fix')
return price_off_peak_fix
else if(LowerCase('Variable Select Parameter'p) = 'price_off_peak_var')
return price_off_peak_var
else if(LowerCase('Variable Select Parameter'p) = 'price_peak_fix')
return price_peak_fix
else price_peak_var
The calculated item dynamically takes the values of a variable based on the value of the Variable Select Parameter parameter. Now, let’s create the Time Series plot with a dynamically changing price variable.
This ends the detailed explanation on how to create a dynamic variable in VA and use it to reduce the number of graphs in a report. I used this approach in a churn prediction project, which you can read about here. Feel free to adapt this method to your specific use case, and comment on this article or reach out to me via email (Mattia.Guglielmelli@sas.com) for any feedback or questions. I hope you found this article helpful, see you next time! 😊
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.