Published on :

Copying Members Between SAS 9 Metadata Groups

This code is also available in: Français
Attention : This code requires administrator privileges.
This program connects to a SAS© 9 metadata server to manage group memberships. It identifies a source group and a destination group by their name, then checks for their existence. If both groups are found, the script iterates through each member of the source group and adds them to the destination group. Progress is reported in the SAS© log. CAUTION: This code is completely incompatible with the SAS© Viya 4 environment because it uses functions (`metadata_resolve`, `metadata_setassn`, etc.) and connection options (`options metaserver...`) that are specific to the SAS© 9 architecture and its metadata server, which no longer exists in SAS© Viya.
Data Analysis

Type : EXTERNAL


The script does not operate on data tables (SASHELP or others). It interacts directly with an external source, the SAS 9 metadata server, to read and write information about identities and groups.

1 Code Block
OPTIONS / %LET
Explanation :
This block configures the connection parameters to the SAS 9 metadata server (address, port, credentials) and defines the names of the source and destination groups in macro variables. These options are specific to the SAS 9 environment.
Copied!
1/* Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
2 * SPDX-License-Identifier: Apache-2.0
3 */
4 
5/* Edit Metadata connection information. */
6 
7options metaserver="meta.demo.sas.com"
8 metaport=8561
9 metauser="sasadm @saspw"
10 metapass="password"
11 metaprotocol=bridge
12 metarepository=Foundation;
13 
14/* Specify the source and destination group names. */
15 
16%let source_group_name='source group';
17%let dest_group_name='destination group';
2 Code Block
DATA STEP
Explanation :
This DATA _null_ block uses SAS 9-specific functions to interact with the metadata server. It resolves the URIs of the source and destination groups (`metadata_resolve`), checks for their existence, then loops through each member of the source group (`metadata_getnasn`). For each member, it retrieves their name (`metadata_getattr`) and associates them with the destination group (`metadata_setassn`). The program stops if either group is not found.
Copied!
1DATA _null_;
2 
3/* Initialize variables. */
4 
5LENGTH type1 type2 id1 id2 src_uri dest_uri mem_uri mem_name $ 50;
6call missing (of _character_);
7 
8/* Define query. */
9 
10src_obj="omsobj:IdentityGroup? @Name=&source_group_name";
11dest_obj="omsobj:IdentityGroup? @Name=&dest_group_name";
12 
13/* Test for the existence of the source group. */
14 
15rc1=metadata_resolve(src_obj,type1,id1);
16src_uri=cats(type1,'\',id1);
17if rc1 < 1 then do; /* If unable to locate, notify and stop. */
18 put "ERROR: SOURCE group &source_group_name not found in Metadata.";
19 stop;
20end;
21 
22/* Test for the existence of the destination group. */
23 
24rc2=metadata_resolve(dest_obj,type2,id2);
25dest_uri=cats(type2,'\',id2);
26 
27if rc2 < 1 then do; /* If unable to locate, notify and stop. */
28 put "ERROR: Destination group &dest_group_name not found in Metadata.";
29 stop;
30end;
31 
32/* Count the number of members in the source group. */
33 
34mem_count=metadata_getnasn(src_uri,"MemberIdentities",1,mem_uri);
35put "NOTE: SOURCE group &source_group_name has " mem_count "members.";
36 
37/* For each member in the source group, add the member to the destination group. */
38 
39do n=1 to mem_count;
40 rc=metadata_getnasn(src_uri,"MemberIdentities",n,mem_uri);
41 rc=metadata_getattr(mem_uri,"Name",mem_name);
42 put "NOTE: Adding " mem_name "to destination group &dest_group_name";
43 rc=metadata_setassn(dest_uri,"MemberIdentities","APPEND",mem_uri);
44 put mem_uri;
45END;
46RUN;
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


Banner
Expert Advice
Expert
Simon
Expert SAS et fondateur.
« This script is a powerful utility for SAS 9.4 administrators needing to clone permissions or organizational structures by duplicating group memberships. By utilizing the SAS Metadata Interface, it automates what would otherwise be a tedious manual task in SAS Management Console. »