By default, SAS Visual Analytics maintains the state of each user's report (or the most recent view of a report) across sessions. The first time a report viewer opens a report, they see it in the state the report was saved. Then, suppose the report viewer changes prompt values and drills into a hierarchy. The next time that user views the same report, SAS Visual Analytics displays the report with the prompt values and drill state from the previous session (unless report state has been disabled).
The report state contains:
Suppose you have a dashboard that displays comprehensive data about a company's operations. You are responsible for different parts of the business and find yourself always selecting the same interactive filters, drill-downs and sorts. You might be interested in saving each report state, so you can easily reapply it later. In this post, we will learn how to use REST API, specifically the Reports API, to do exactly this.
You can find the full code on my GitHub.
The documentation for the Reports API can be found here. For an introduction to REST API, ETags, and how to read the documentation, read this post.
We need to understand the following key points:
To save the report state, we perform the following steps:
To apply the report state later, we need to:
Open any report in view mode (for example Warranty Analysis from SAS Content/Products/SAS Visual Analytics/Samples) and change the report state by selecting prompt values, adding labels, changing object types and sorts:
Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
Note that if the report author gave you viewer capabilities, you can also change data item assignments, filters, ranks and display rules. The next step is to get the report ID. To find the report ID, you can click on the Report Menu, Copy embeddable markup and copy the part of the reportUri after the last forward slash:
Next, in SAS Studio, open a new SAS program and paste the code from the repository (see above) to save the state. Change the value for the report ID (line 1) and the location to save the report state (line 4). You may click on SAS Server on the left pane and find a folder in which you want to save the report state, and right-click on it to insert the path into the program. Ensure you add a filename at the end:
Run the code. If you get a 401 HTTP response running the code, just reset the SAS session and try again. You know that the run is successful by checking the log and checking whether the report state file has been saved:
Note, you can open and view the file - the details on the report state are usually at the very end. Then, return to SAS Visual Analytics and change the report state in some way - this is just so we can have a different state before we reapply the saved state. Then, return to SAS Studio and repeat the abovementioned steps with the code to apply a report state. Here, you can also give a label to the new state on line 2:
Run the code and check the return codes in the log - they should be 200, 201 or 204 (see screenshot):
Lastly, return to Visual Analytics and reopen the page with the report:
You should see the state reapplied:
In this post, you have access to the code (see above) needed to use the reports API to save and then apply a report state. In the next post, we will integrate this code into a SAS® Viya Job, with which a report viewer can do this without interacting with the code.
Find more articles from SAS Global Enablement and Learning here.
Visit the Tips & Tricks page for setup guidance, demos, and practical examples that show how Copilot supports your workflows.
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.