Published on :
Administration CREATION_INTERNE

Extracting User IDs by Group (SAS 9 Metadata)

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
This program establishes a connection to a legacy SAS© 9 metadata server. It then queries the metadata to find a specific group, list its members (persons), and retrieve their associated login information. Important note: This code is explicitly designed for SAS© 9.x (using the metadata interface) and will not work on a standard SAS© Viya 4 installation without access to an external SAS© 9 metadata server.
Data Analysis

Type : CREATION_INTERNE


Data is dynamically generated by querying the metadata server using SAS `metadata_*` functions.

1 Code Block
GLOBAL OPTIONS
Explanation :
Configuration of SAS 9 metadata server connection options (address, port, user, password) and definition of the macro variable for the group to be analyzed.
Copied!
1options metaserver="meta.demo.sas.com"
2 metaport=8561
3 metauser="sasadm @saspw"
4 metapass="Password"
5 metarepository=Foundation
6 metaprotocol=Bridge;
7 
8/* Provide a group name you would like to query. */
9%let groupname=SAS Administrators;
2 Code Block
DATA STEP Data
Explanation :
Main DATA STEP that navigates the metadata structure. It resolves the Group object, iterates through its member identities, then descends to the Login objects to extract the User ID and authentication domain, storing the result in the `usertab` table.
Copied!
1DATA usertab;
2LENGTH type id group_uri group_name per_uri per_name log_uri user_id ad_uri ad_name $ 256;
3call missing(type,id,group_uri,group_name,per_uri,per_name,log_uri,user_id,ad_uri,ad_name);
4obj="omsobj:IdentityGroup? @DisplayName='&groupname'";
5groupCount=metadata_resolve(obj,type,id);
6put groupCount=;
7IF groupCount = 0 THEN DO;
8 put "ERROR: No groups named &groupname defined in the repository.";
9 stop;
10END;
11IF groupCount > 0 THEN DO n=1 to groupCount;
12 rc=metadata_getnobj(obj,n,group_uri);
13 rc=metadata_getattr(group_uri,"DisplayName",group_name);
14 put group_name=;
15 memCount=metadata_getnasn(group_uri,"MemberIdentities",1,per_uri);
16 IF memCount > 0 THEN DO m=1 to memCount;
17 rc=metadata_getnasn(group_uri,"MemberIdentities",m,per_uri);
18 rc=metadata_getattr(per_uri,"DisplayName",per_name);
19 logCount=metadata_getnasn(per_uri,"Logins",1,log_uri);
20 IF logCount > 0 THEN DO o=1 to logCount;
21 rc=metadata_getnasn(per_uri,"Logins",o,log_uri);
22 rc=metadata_getattr(log_uri,"UserID",user_id);
23 rc=metadata_getnasn(log_uri,"Domain",1,ad_uri);
24 rc=metadata_getattr(ad_uri,"Name",ad_name);
25 OUTPUT;
26 call missing(log_uri,user_id,ad_uri,ad_name,group_name,per_name);
27 END;
28 END;
29END;
30keep group_name per_name ad_name user_id;
31RUN;
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. SPDX-License-Identifier: Apache-2.0