BookmarkSubscribeRSS Feed

Dynamically Filter a SAS Visual Analytics Report by the Logged-In User in Viya 4

Started 3 hours ago by
Modified 3 hours ago by
Views 31
Introduction:

In SAS Visual Analytics, reports can present data from multiple users, departments, or business areas within a single view. In some scenarios, however, users may want to focus first on data that is relevant specifically to them while still having the flexibility to view all available data when needed. For example, a report might contain records owned by many users, but each user would prefer to quickly filter the report to records associated with their own user ID. To improve usability, we’ll explore how to combine a user identity lookup table, row-level security (RLS), data source mapping, and report interactions to create a simple “My Data / All Data” filtering experience in SAS Visual Analytics. This article is going to walk you through detailed steps on how to achieve this objective.

 

Main Section:

Let me first show you what the result would look like in an example.

This is a simple VA report that contains a button bar and a list table. The table only contains two variables, which are book name and author name. Here is the demonstration on the two conditions you can see with the example report, helping you to dynamically filter the report by the logged-in user.

 

Condition1 : If you click the button bar, it automatically filters to display the data rows specific to your logged-in user. In my case, it displays the book name with a author name that is identical to my id.

first_pics.png

Condition2 : If you unclick the button bar, it displays all the book name from the source table.

second_pics.png

 

Here are the steps on how you can create such kind of VA report in a simplified example:

  1. First of all, you need to build a CAS user lookup table from SAS identities REST API and securing it with dynamic row-level security. This user lookup table will be used in the actual use case. I have created a sample code for you that you should be able to run directly in SAS Studio. Please also keep in mind that only the admin should have the privilege to execute this code.  In addition, the table created in this sample code is called userlookup. If there is a naming conflict with the original tables existing in your environment feel free to rename and modify the code shared.

    cas cs;
     
    filename idresp temp;
     
    proc http
        url="https://sas-identities/identities/users?limit=100000"
        oauth_bearer=sas_services
        out=idresp
    ;
    headers "Accept"="application/json"
    ;
    run;
     
    libname idjson json fileref=idresp;
     
    libname public cas caslib="public";
     
    data public.userlookup_session(keep=id name replace=yes);
        set idjson.items;
    run;
     
    proc cas;
    action table.droptable /
        caslib="public",
        name="userlookup",
        quiet=TRUE;
    action table.promote /
        caslib="public",
        name="userlookup_session",
        targetcaslib="public",
        target="userlookup",
        drop=TRUE;
    run;
    action accessControl.assumeRole /
        adminRole="SUPERUSER";
    action accessControl.updSomeAcsTable /
        acs={{  
            caslib="public",
            table="userlookup",
            permission="SELECT",
            permType="GRANT",
            identityType="GROUP",
            identity="*",
            filter="id='SUB::SAS.Userid'"
        }};
    run;
    quit;
     
    cas cs terminate;​

     

  2. Go to the VA report, and then add the user identity table you just created (USERLOOKUP) as one of your source data.
    fourth_pics.png

  1. Add another source data and create an object you would like to display in your VA report. In my test case, I added a list table.
    In this second source data, it is required to have a column which contains value of id that can be mapped with the userlookup table id value. In my case, I added the author column to record the user id value that is identical to my user lookup table.
    fifth_pics.png

 

  1. Add a control object and assign id column from userlookup table as data role. I choose button bar in my use case.
    Then under Actions pane, set the object links to the list table created and mapped the variables from two source tables. (In my case, I mapped "id" column from USERLOOKUP table to "author" column from TEST_INPUT_DATA table.)
    sixth_pics.png
    seventh_pics.png

 

  1. After the above the configuration, you can filter to control the display of the newly added object according to your requirement.
    Condition1 : If you click the button bar, it filters to display the data rows only specific to your logged in user.  
    first_pics.png
    Condition2 : If you unclick the button bar, it display all data rows.
    second_pics.png

Conclusion:

By combining a user identity lookup table with row-level security and report interactions, users can quickly focus on data relevant to them while retaining the flexibility to view all available data. This approach creates a more personalized reporting experience, simplifies navigation, and makes SAS Visual Analytics reports more intuitive and user-friendly.

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

Viya Copilot Motion Graphic.gifViya Copilot Motion Graphic

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 Labels
Article Tags