BookmarkSubscribeRSS Feed

Update user’s preferences based on group membership

Started ‎02-05-2019 by
Modified ‎03-04-2021 by
Views 2,947

Customers are requesting to update user preferences such as themes, units for distance, etc, based on group membership. SAS Viya enables users to update their own preferences through the user interface. However if an administrator needs to change those, it can be harder as they are set at user level and not at group level. Using code we can now update large amounts of users or user groups pretty easily.


SAS Viya is built on REST architecture. It makes it really easy for administrator to call the REST APIs to achieve actions that are not implemented in the user interface or to automate actions. Here are the high level steps that are required to update the preferences: configure the SAS environment for API use, download the Python code I've provided, determine the users for which the preferences should be updated, then finally, execute the Python code from command-line.


In order to execute the code, you should have access with administrative rights to an environment where SAS Viya and Python are installed (it does not necessarily have to be on the same machine).


Configure the SAS environment for API use

Configuring the SAS environment for API use is described on Here are the steps to be performed by a SAS administrator:

  1. Register a client application
  2. Configure Cross-Origin Resource Sharing

To validate the configuration, execute the following line from the command-line. Be sure to use your environment specifics for the the values in bold below:


curl -X POST "" \
      -H "Content-Type: application/x-www-form-urlencoded" \
      -d "grant_type=password&username=USERID&password=PASSWORD" \
      -u "app:mysecret"


The curl command should be written on one line.


If the authentication is successful, a JSON string is returned with an access_token (see short version below).




If it fails, an error like the one below will appear:


{"error":"unauthorized","error_description":"Bad credentials"}


If you get an error, please make sure that the command contains the correct information. If the parameters are correct, it might indicate that the step 1 and 2 were not performed properly. You should validate with the administrator that the steps were properly achieved and that the parameters in the curl command are correct.


Python configuration

In order to execute the provided code, we will need an environment where Python is installed with the required package.

  1. Download the code.
  2. Copy the file to the machine where Python is installed. I saved it to my /home directory.
  3. Execute the following command to install the required Python module:  pip install --user requests

Determine the users or groups to be updated

Now that we have both the SAS environment ready for API use and the Python environment ready, we need to identify which user or group of users we want to update the preferences for.


We will need the ID of the user or group.

  1. Open SAS Environment Manager in a browser:
  2. Enter the credentials for a user with administrator privileges.
  3. When prompted for Assumable Groups, select Yes.




  4. In SAS Environment Manager select Users section and choose the group or user you want to update.




  5. Note down the ID of the user or group for later usage.


Execute the code

In order to execute the code, we need to know which preference should be updated and which value can be set. The provided Python code contains these name/value pairs in the area names POSSIBLE VALUES:




  • sas.welcome.suppress enables or disables the Welcome screen when the user connects for the first time.
  • hides or shows the Quick Access pane in SAS Drive
  • VA.geo.drivedistance.unit switches between kilometers and miles when calculating drive distance in Geo maps.
  • OpenUI.Theme.Default defines the theme to be used in the Visual Analytics User Interfaces.

Now that we have identified the users/groups and the preference/value, we can execute the code which will update the SAS Environment. As mentioned earlier, we will use the command-line to execute it.

  1. Start a command prompt on the machine where Python is installed.
  2. Navigate to the location where the Python code has been saved.
  3. Type the adapted command based on your needs.
    1. Example for a single user




    2. Example for a group of users




    3. To get help: python ./ --help




    4. Press Enter to execute the code.
    5. During the execution, you should get information about the update status.


      Preference for "VA.geo.drivedistance.unit" has been set to "miles" for user sbxxab

    Where can you get more information?


Interesting post Xavier.  Are the identities and preferences services you are using in your Python script documented anywhere?

Thank you for the feedback. doesn't cover the identities and preferences end-points. You can call those rest API's to get a better idea on how they can be used. A GET request will return the possible verbs and their parameters in a JSON object. If you need more information, please let me know and I will do my best to answer your questions. 

Great info and great script @XavierBizoux . I wanted to provide a link to a series of SAS users blogs I wrote on REST APIs and SAS Viya for further info.


@rrc102 , this link for SAS Viya Idenity Management may have some of the info you are looking for. 

Version history
Last update:
‎03-04-2021 04:10 AM
Updated by:



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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