BookmarkSubscribeRSS Feed

How to prompt for a date range in a SAS VA report – Example 2 Slider (Single Value)

Started ‎01-21-2020 by
Modified ‎06-04-2020 by
Views 5,885

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:

Example 2: Slider (Single Value)

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.

 

01_Example2_Slider_SingleValue-1024x958.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.

 

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:

  1. Add a Slider (Single Value) control object to the report canvas and assign Roles
  2. Create a parameter and assign to control object’s Roles
  3. Create two calculated data items for the lower and upper date boundaries
  4. Define Filters for report objects using the calculated date boundaries
  5. (Optional) Define Display Rules for report objects that match the selected value

Step 1: Add a Slider (Single Value) control object to the report canvas and assign Roles

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.

 

02_AddSlider.png

 

Next, we need to assign the Roles and then using the Options pane change the Input Style to be Single Value.

 

03_Roles_Options-1024x281.png

Step 2: Create a parameter and assign to control object’s Roles

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.

 

04_CreateParameter.png

 

Next we need to assign this parameter to the Slider (Single Value) control object’s Roles so that it stores the value selected.

 

05_AddParameterRole-1024x367.png

Step 3: Create two calculated data items for the lower and upper date boundaries

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.

 

06_NewCalculatedItem.png

 

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:

 

07_LowerDateBoundary-1024x515.png

 

Repeat the steps to create a new Calculated item. Here is the expression for the 5 Days After upper date boundary:

 

08_UpperDateBoundary-1024x515.png

 

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.

 

08.5_BoundaryExpressionUpdate.png

Step 4: Define Filters for report objects using the calculated data boundaries

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.

 

09_ListTable_Filter-1024x411.png

 

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.

 

10_FilterExpression.png

 

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.

 

11_CommonFilter-1024x409.png

 

Now, when we activate the Bar Chart below, this Common Filter will be available to apply.

 

12_BarChart_Filter-1024x642.png

 

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.

Step 5: (Optional) Define Display Rules for report objects that match 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.

 

13_NewCalculatedItem.png

 

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.

 

14_HighlightingFlagCalculatedItem.png

 

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.

 

15_ListTable_Rule-1024x642.png

 

Configure the new display rule such that when the SelectedDateFlag is greater than 0, color the background for the row yellow.

 

16_ListTable_RuleExpression.png

 

Repeat the steps for the Bar Chart object, except the display rule will be for the graph element.

 

17_BarChart_RuleExpression-1024x642.png

 

Success! Here’s a summary of the technique for Example 2: Slider (Single Value)

  1. Add a Slider (Single Value) control object to the report canvas and assign Roles
  2. Create a parameter and assign to control object’s Roles
  3. Create two calculated data items for the lower and upper date boundaries
  4. Define Filters for report objects using the calculated data boundaries
  5. (Optional) Define Display Rules for report objects that match the selected value

How to prompt for a date range in a SAS Visual Analytics report (series of articles):

Other References

Comments

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.

Version history
Last update:
‎06-04-2020 01:01 PM
Updated by:
Contributors

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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