Published on :
Administration INTERNAL_CREATION

Deleting Users from Metadata

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
This script first configures the connection to the metadata server (SAS© Metadata Server). It then generates a temporary table containing the user names to be deleted via datalines. Finally, it executes a DATA _NULL_ step to iterate over this list, delete the associated logins (metadata_delassn) and the person object (metadata_delobj), with error and log management.
Data Analysis

Type : INTERNAL_CREATION


User names are defined directly in the code via the DATALINES statement.

1 Code Block
DATA STEP Data
Explanation :
Definition of metadata server connection options and creation of the 'work.delusers' table containing the IDs to be deleted.
Copied!
1options metaserver='meta.example.com'
2 metaport=8561
3 metaprotocol='bridge'
4 metauser='sasadm @saspw'
5 metapass='password'
6;
7
8DATA work.delusers;
9 INFILE DATALINES truncover;
10 LENGTH username $ 255;
11 call missing (of _character_);
12 INPUT username $1-255;
13 DATALINES;
14 deltest
15 deltest1
16 deltest2
17 del test3
18;;
19RUN;
2 Code Block
DATA STEP
Explanation :
Effective deletion using metadata functions: construction of the person object URI, deletion of associated logins, then deletion of the user object, with logging in the journal.
Copied!
1DATA _null_;
2 
3 /* Read in the data set. */
4 SET work.delusers;
5 
6 /* Build a URI from the supplied user name. */
7 obj="omsobj:Person? @Name='"||trim(username)||"'";
8 
9 /* Delete the Logins associated with the user. */
10 rc=metadata_delassn(obj,"Logins");
11
12 /* Check if the delete of Logins was successful. */
13 
14 IF rc ne 0 THEN DO;
15 /* Throw an error if the login delete action failed. */
16 put "ERROR: Failed to delete associated logins for user " username ". " rc=;
17 END;
18 /* If deleting logins was successful, move on to deleting the user. */
19 ELSE DO;
20 /* Write a note to the log indicating the delete of logins was successful. */
21 put "NOTE: Successfully deleted logins associated with user " username". Attempting to delete user.";
22 
23 /* Delete the user object. */
24 rc=metadata_delobj(obj);
25 
26 /* Check if delete was successful. */
27 IF rc ne 0 THEN DO;
28
29 /* If not, throw an error. */
30 put "ERROR: Failed to delete user " username ". " rc=;
31 END;
32 
33 /* If so, note that delete was successful. */
34 ELSE put "NOTE: Successfully deleted user " username ".";
35 END;
36RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.