BookmarkSubscribeRSS Feed

SAS Visual Analytics: Using an expression-based parameter to drive a dynamic reference line

Started 3 weeks ago by
Modified 3 weeks ago by
Views 188

In this post, I will create a dynamic reference line for a line chart using expression-based parameters. For this example, I will use the SASHELP.ORSALES table. The table contains data over total retail prices, profit of different products over different quarters. I have created a line chart displaying Total Retail Price in USD by Quarter:

 

01_NR_42818_11_1_OriginalChart.png

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

 

I now want to add a reference line that changes dynamically with the data. Specifically, the reference line should be the average of Total Retail Price in USD over all quarters. To achieve this, I first create an expression-based parameter calculating this. In the Data pane on the left, click on New data item and Parameter:

 

02_NR_42818_11_2_NewParameter.png

 

03_NR_42818_11_3_NewParameter.png

 

Enter the following expression:

 

AggregateTable(_Avg_, Table(_Sum_, Fixed('Quarter'n), 'Total Retail Price in USD'n))

 

 

Note: If I had only one row per quarter, I could have used a more simple expression:

 

Avg(ForAll, Profit)

 

However, here there are multiple rows per quarter. The AggregateTable function takes the sum of all the rows per quarter, and then averages over those sums.

 

 

Click OK.

 

Now we can add the reference line based on this parameter. With the line chart selected, in the Options pane on the right, expand the Reference Lines section and click on + New reference line:

 

04_NR_42818_11_4_NewReferenceLine-1024x513.png

 

For Value, click on the down arrow and select Average of Total Retail Price. I also changed the line style and color to make the reference line more distinguishable:

 

05_NR_42818_11_5_FinalChart-1024x513.png

 

 

Conclusion and Further Reading

 

This is only one example of how to use expression-based parameters to drive a dynamic reference line.  For a deep dive example of using the AggregateTable function and dynamic references lines, see this article:  SAS Visual Analytics: Use a parameter to drive a dynamic reference line. For more information see the SAS Documentation: Working with Parameters in Reports.

 

 

Find more articles from SAS Global Enablement and Learning here.

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

Viya Copilot Motion Graphic.gif

Ready to see what SAS Viya Copilot can do?

Visit the Tips & Tricks page for setup guidance, demos, and practical examples that show how Copilot supports your workflows.

Get Started →

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Tags