I’ve broken this topic down into a four-part series to make it easier to consume and to save you from copious amounts of scrolling. The accompanying video tutorial is available and the below examples are linked to their corresponding timestamps in the video.
The control objects and examples I will cover in this blog series include:
The second example will not exactly prompt for a date range, but instead display a fixed number of days given the selected date. In this example, I have configured the report objects to display the 5 days prior and 5 days after the selected date value. I’ve also configured a display rule to highlight the selected date value to allow for easy readability.
Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
If you are interested in how to highlight a selected value check out this article or video tutorial.
Since I want to dynamically calculate the date range to display the 5 days prior and 5 days after the selected date we will not use the Report or Page prompt areas. This means we will need to manually configure filters for any objects that we want to display my custom date range.
The technique used in this example will follow these steps:
Use the page’s overflow menu to Expand page controls so that it is easy to see where you are dragging the Slider control object. Do not place the control object in the Page prompt area, but directly under it in the report canvas.
Next, we need to assign the Roles and then using the Options pane change the Input Style to be Single Value.
Now we will need to create a parameter to store the selected date value from the Slider (Single Value) control object so that we can dynamically calculate the date filter boundaries.
From the Data pane, use the New data item menu and select Parameter. Enter the new parameter information for the date data item and be sure you select the correct Type.
Next we need to assign this parameter to the Slider (Single Value) control object’s Roles so that it stores the value selected.
Now we can create the calculated data items to serve as our date filter boundaries. Recall that this example will filter to display the 5 days prior and 5 days after the selected date value.
From the Data pane, use the New data item menu and select Calculated item.
Remember we are working with SAS dates, which means SAS calculates the number of days since January 1, 1960 so we will need to use the TreatAs function to be able to use the subtraction and addition expressions to calculate the 5 days prior and after. Note that this means we will use 6 to move our date so as not to include the selected date value.
Here is the expression for the 5 Days Prior lower date boundary:
Repeat the steps to create a new Calculated item. Here is the expression for the 5 Days After upper date boundary:
Note: Thanks to my dedicated reader that pointed out that I do not need to wrap the numeric 6 in a TreatAs function! I was on a roll in my recording and dragged an extra TreatAs function – but the expression will work fine with just the 6 in either the subtraction or addition operation.
Now we have our date boundaries which are being dynamically calculated based on the parameter that is being driven from the Slider (Single Value) control object. Next, we need to apply a Filter to our report objects.
Select the report object, in this case I’ve selected the List Table object. Then use the Filter pane and from the New filter menu select Advanced filter.
Next build the filter expression for our date data item using the between inclusive condition and our calculated data items as the lower and upper boundaries.
If you want to apply this same filter to multiple report objects, then the easiest way to do that is to create a Common Filter that can be reused. With the List Table still active, from the Filters pane, use the filter’s overflow menu and select Change to common filter. Pro tip: give your filters meaningful names to help identify them when you have many Common Filters.
Now, when we activate the Bar Chart below, this Common Filter will be available to apply.
Complete! Now we have successfully configured the Slider (Single Value) control object to drive a dynamic 11 day window filter which displays 5 days prior and 5 days after the selected value.
Let’s go ahead and configure the dynamic highlighting. If you are interested in other examples of how to highlight a selected value check out this article or video tutorial.
We will need to create a calculated data item to flag which rows need to be highlighted. In this case, we need to flag the rows that match the selected value from the Slider (Single Value) control object. Remember how we know which value was selected? The parameter! That’s right, we store the selected value in our parameter, SelectedDayParameter.
From the Data pane, use the New data item menu and select Calculated item.
We will use the below boolean expression to check if the row’s date value matches the parameter value. If yes, then flag the row, or in our case, assign our new calculated data item to 1, else assign it 0.
Now we can define a Display Rule for our report objects to highlight any instance where the rows are greater than 0.
Select a report object, in this case I’ve selected the List Table object. From the Rules pane, use the New rule menu and select SelectedDateFlag.
Configure the new display rule such that when the SelectedDateFlag is greater than 0, color the background for the row yellow.
Repeat the steps for the Bar Chart object, except the display rule will be for the graph element.
Success! Here’s a summary of the technique for Example 2: Slider (Single Value)
How to prompt for a date range in a SAS Visual Analytics report (series of articles):
This may not be related to the post but I was wondering if it is possible in SAS VA to create multiple date ranges in one view?
For example: Say I have revenue (x-axis) and profit (y-axis). I would like to create a view that demonstrates revenue across quarters (i.e., multiple date ranges).
I am not entirely sure if this is a time series? I know this is possible in Tableau.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.