Published on :

Massive addition of groups in SAS 9 metadata

This code is also available in: Español Français
Attention : This code requires administrator privileges.
This program is designed for the SAS© 9.x environment. It connects to the Metadata Server using the provided options. It identifies a target group defined by the macro variable 'addgroup', lists all 'IdentityGroup' objects with 'UserGroup' PublicType, and systematically adds them as members of the target group using metadata interface functions.
Data Analysis

Type : EXTERNE


Data is manipulated directly on the SAS metadata server (OMR) via specific functions (metadata_getnobj, metadata_setassn).

1 Code Block
OPTIONS
Explanation :
Configuration of the SAS 9 metadata server connection and definition of the target group name.
Copied!
1options
2 metaserver="meta.demo.sas.com"
3 metaport=8561
4 metauser="sasadm @saspw"
5 metapass="password"
6 metarepository=Foundation
7 metaprotocol=bridge;
8 
9%let addgroup='Red Test';
2 Code Block
DATA STEP
Explanation :
Main logic: retrieval of metadata object URIs, iteration over the list of existing groups, and updating of target group associations.
Copied!
1DATA _null_;
2 /* Initialize variables. */
3 LENGTH type id addgroup_uri group_uri group_name $ 50;
4 call missing (of _character_);
5 
6 /* Set queries for all groups and for specific group. */
7 group_obj="omsobj:IdentityGroup? @Name=&addgroup";
8 allgrp_obj="omsobj:IdentityGroup? @PublicType='UserGroup'";
9 
10 /* Get URI for the group name defined in the 'addgroup' macro variable above. */
11 rc=metadata_getnobj(group_obj,1,addgroup_uri);
12 
13 /* Count all groups. */
14 group_count=metadata_resolve(allgrp_obj,type,id);
15 
16 /* If there are groups, do this for each group... */
17 IF group_count > 0 THEN DO n=1 to group_count;
18 /* Get the URI of the group. */
19 rc=metadata_getnobj(allgrp_obj,n,group_uri);
20 /* Get the name of the group. */
21 rc=metadata_getattr(group_uri,"Name",group_name);
22 
23 /* If the group name is that of the addgroup, do nothing. */
24 IF group_name = &addgroup THEN;
25 ELSE DO; /* If not... */
26 put "Adding " group_name;
27 /* Add it to the membership. */
28 rc = metadata_setassn(addgroup_uri,"MemberIdentities","APPEND",group_uri);
29 END;
30 END;
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