Need a Dynamic X-Axis with Your SAS Visual Analytics Report?

I like to read the SAS Visual Analytics area of SAS Communities site. From the site I have overcome issues I had as well as learned other ways to think how you can solve common issues. As many long time SAS users know – there’s always more than one way to accomplish something with SAS! Recently, as user was asking how to expand parameters to create a dynamic x-axis. Using his partial example, here’s how it can be done.

Creating a Dynamic X-Axis

The user wanted the X-Axis on his chart to change based on the button bar selection. Notice that when I click on each button, the X-Axis values change based on my selection.If I click cat2 then the x-axis shows the 2a and 2b instead of the ABC values from cat1.


You can use a parameter to accomplish this task. The parameter can pass the desired category to the Category role.  Here’s the sample data set that I used to create this graphic. In my example, I will use cat1 to create a custom category. Then the custom category will control the rows and the selected data item.va_param05

If you click the cat2 button, it filters the data to show rows 4 and 5. With the parameter, it says display the values from cat2 data item. Study the data and then the graphic above to better understand what is being displayed. Remember – using this method is pre-filtering the data!

Adding a Parameter

Here’s how I setup this example. You try it.

  1. Run the following program in BASE SAS, SAS Studio, or even SAS Enterprise Guide.  It creates a data set called parameter_example.
    [Or you download the text file version  and import it as a text file into SAS Visual Analytics, if allowed at your site.]

    data parameter_example;
    input cat1 $ cat2 $ cat3 $ cat4 $ num1 ;
    A X  X  X  0.21
    B X  X  X  0.25
    C X  X  X  0.29
    D 2a X  X  0.81
    E 2b X  X  0.89
    F X  3a X  0.41
    G X  3b X  0.49
    H X  X  4a 0.01
    I X  X  4b 0.06
    J X  X  4c 0.09
  2. Open the SAS VA Designer, start a new report and add the Parameter_Example data source.
  3. Create a new character parameter call Parameter 1.
  4. Right-click on the cat1 data item and select New custom category called Custom Cat VA.
    Your category should look like the following example when complete:
  5. Add a new calculated item called Calc Item.
    Your item should look like this following item when complete:
  6. Create your report layout as follows:
    • Add a button bar to the section area.
      • Assign the following roles:   Category = Custom Cat VA; Parameter = Parameter 1
    • Add a bar chart to the design area:
      • Assign the following roles:  Category = Calc Item; Measure = Num1
  7. Try it out!

You could also use this method with a measure. If you wanted to change the chart to show the minimum value or the maximum value – you could do it with the click of the button. I’ll let you work that one out for yourself.

Hustle over to the SAS Communities page to see what you can learn!

Never miss a BI Notes post!

Click here for free subscription. Once you subscribe you'll be asked to confirm your subscription through your email account. You email address is kept private and you can unsubscribe anytime.