BookmarkSubscribeRSS Feed

Creating cleaner reports: Using parameters and controls to reduce graphs in SAS VA

Started 4 weeks ago by
Modified 4 weeks ago by
Views 977

Introduction

 

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:

  • price_mid_peak_fix
  • price_mid_peak_var
  • price_off_peak_fix
  • price_off_peak_var
  • price_peak_fix
  • price_peak_var

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).

 

 

Step 1: Prepare the Data

 

First, we’ll prepare the data needed to reproduce the result shown in the video.

  • The price_data_raw table has been loaded into memory using the Import Local Files section of the Import tab in SAS Data Explorer:

 

Screenshot 2025-01-13 151527.png

 

  • The va_dummy_data table has been created, promoted to global scope, and saved as a .sashdat file using the code in the attached Data preparation.sas file. This dataset consists of a single variable, dummy_data, with a number of rows equal to num_rows, and contains values ranging from 1 to num_vars (which is set to 6 in this example).

    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.

 

 

Step 2: Set up the report in VA and create a custom category

 

Now, we’ll create a new report in SAS Visual Analytics and set up the necessary components.

  • Add both the price_data and va_dummy_data tables to the report via the Data pane (the topmost icon on the left pane).

 

Screenshot 2025-01-09 160223.png

 

  • With the va_dummy_data data set selected, create a new custom category by clicking New data item --> Custom category.

 

Screenshot 2025-01-13 135314.png

 

  • Name the custom category Variable Select and set Group by to Distinct values.
  • Next, add new groups until you have a number of groups equal to num_vars (6 in my case): Group 1 to num_vars-1 and the Remaining Values group. Rename the first num_vars-1 groups to distinct variable names and assign a value to each. For the Remaining Values group, change the default name Other to the last price variable name you didn't use yet.

 

Screenshot 2025-01-13 112249.png

Screenshot 2025-01-13 112311.png

 

  • Create a new character parameter called Variable Select Parameter by selecting New data item --> Parameter and set its type to Character.
  • Drag a Drop-down list object to the canvas, flag the Required option and change the title to Select a price variable to display the corresponding Time Series plot.
  • Link the Variable Select Parameter parameter to the drop-down list. This can be done in the Actions pane by selecting the parameter through the drop-down list under Parameter Links.

 

Screenshot 2025-01-13 141711.png

 

The parameter allows us to create a connection between the Control object and the dynamic variable, which we'll create in the next step.

 

 

Step 3: Create a Calculated Item

 

  • Select the price_data data set in the Data pane and click New data item --> Calculated Item.
  • Name it Price Variable and define it using the following code:
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

 

Screenshot 2025-01-13 142154.png

 

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.

 

 

Step 4: Add the Time Series Plot to the report

 

  • Add a Time series plot object to the canvas below the drop-down list and assign the roles as follows:
    • Time axis: price_date
    • Measure: Price Variable 
  • (Optional) The dynamic variable name is static, i.e. it doesn't change based on the parameter value. Therefore, at the moment, the user only knows which variable is being displayed from the drop-down list selection. To make the displayed variable more explicit, a dynamic title can be defined:
    • Remove the plot title by selecting No title in the Options pane.
    • Add a Text object above the plot, insert the Variable Select Parameter by selecting it from the Data dropdown list on the toolbar, i.e. the rightmost button, and complete the title as desired.

 

Screenshot 2025-01-13 144737.png

 

 

Conclusions

 

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! 😊

Version history
Last update:
4 weeks ago
Updated by:
Contributors

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


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