BookmarkSubscribeRSS Feed

View activity records in SAS Viya

Started ‎06-29-2023 by
Modified ‎06-29-2023 by
Views 1,849

As part of ongoing efforts to enhance SAS Viya administration capabilities, we will introduce in this blog post a new program within the pyviyatools repository. is a Python script designed to retrieve and analyze activity records from the SAS Viya environment. These activity records are a kind of audit record that provide insights into the operations and usage patterns of your SAS Viya deployment, enabling administrators and audit compliance folks to better understand at a high-level how the Viya deployment is being used by end users.


The concept of activities has been introduced within SAS Viya's audit service to provide a way to inject higher-level business logic into the auditing process. Traditionally, auditing focuses on low-level technical details, providing limited visibility into the actual usage patterns of different endpoints, making it somewhat challenging to derive meaningful insights. With the introduction of activities, the auditing framework gains a new, higher-level perspective to make auditing more intuitive and understandable. This improved understanding allows for better analysis, troubleshooting, and decision-making based on the audit data.


The audit service routinely loads activity data, which is stored in PostgreSQL, into the SystemData.AUDIT_ACTIVITIES table in CAS for reporting. The User Activity VA report provides a way for users to visualise audit data, but there is not yet a way to do the same for activity data, nor to view the raw activity records themselves.


Enter, the latest addition to the growing pyviyatools repository.


To get started with, you can simply clone the pyviyatools GitHub repository and install the necessary dependencies. When it is run, leverages the SAS Viya REST API to retrieve activity records from the SAS Infrastructure Data server. It also allows you to specify the time range and filters to narrow down the scope of the records you want to retrieve. These records can not yet be surfaced from the sas-viya CLI's audit plug-in, which instead retrieves only the 'regular' audit records.


The program supports multiple output formats, including CSV (default), JSON, and Pandas DataFrames. This flexibility allows you to seamlessly integrate the retrieved activity records into your preferred reporting tools or visualization platforms. Leveraging scheduling tools like cron, you can automate the execution of at regular intervals, enabling the continuous capture of activities within the SAS Viya environment.


The simplest way to execute the program is to simply run it without any additional parameters:  




id ,type ,action ,administrativeAction ,state ,user ,application ,timeStamp ,remoteAddress


As the sample output above shows, activity records are currently capturing predominantly security-type records. This is expected to grow in future releases to include records from more and more applications for capturing additional types of user actions.


You can also add additional flags for filtering the output. For example, you can narrow the results by user, application, action, or time range. Consult the built-in documentation to view all options: -h




usage: [-h] [-l LIMIT] [-t TYPE] [-a APPLICATION]
                             [-c ACTION] [-d ADMIN_ACTION] [-s STATE]
                             [-u USER] [-A AFTER] [-B BEFORE] [-S SORTBY]
                             [-o {csv,json,simple,simplejson}]

optional arguments:
  -h, --help            show this help message and exit
  -l LIMIT, --limit LIMIT
                        Maximum number of records to display
  -t TYPE, --type TYPE  Filter by entry Type
                        Filter by entry Application
  -c ACTION, --action ACTION
                        Filter by entry Action
  -d ADMIN_ACTION, --admin-action ADMIN_ACTION
                        Filter by Administrative Action
  -s STATE, --state STATE
                        Filter by entry State
  -u USER, --user USER  Filter by Username
  -A AFTER, --after AFTER
                        Filter entries that are created after the specified
                        timestamp. For example: 2020-01-03 or
  -B BEFORE, --before BEFORE
                        Filter entries that are created before the specified
                        timestamp. For example: 2020-01-03 or
  -S SORTBY, --sortby SORTBY
                        Sort the output ascending by this field
  -o {csv,json,simple,simplejson}, --output {csv,json,simple,simplejson}
                        Output Style


Understanding how your SAS Viya environment is being used can help SAS Viya administrators to meet regulatory obligations, monitor and review security aspects, troubleshoot effectively and better align platform usage with broader business objectives. By leveraging the power of Python and the flexibility of SAS Viya's REST API, enables the retrieval and analysis of activity records to provide valuable insights into user patterns for administrators and auditors.



Find more articles from SAS Global Enablement and Learning here.



Working in Pharmaceutical industry and currently deploying SAS VIYA, I'm interested by your post. 

I need to have audit trail to log user activity in terms of creation, modification, deletion of filed, folders, programs, etc. (in sas compute at least where we have set up a direct access to a NFS share). 

I will need help to set-up this.

Do you have any advices to share with us?

Kind regards, 

Version history
Last update:
‎06-29-2023 10:42 PM
Updated by:


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

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