BookmarkSubscribeRSS Feed
Lapis Lazuli | Level 10

This is more a metadata question than a stored process question. Am asking it here since there is no metadata forum and what I need to do is needed to support a number of stored processes.

I have a number of metadata users already defined (about 800). And I have 5 groups that have been created (currently empty). I can get the list of users and groups using the mduextr macro. And I have the logic I need to assign each user to the group they belong to (each user belongs to 1 and only 1 group).

Before writing the code myself I thought that this is something that there would be a sample for. And I did find samples that will do this for users and groups that don't exist in the metadata (the samples described in And based on a quick look it does not appear that it can be easily reverse engineered.

Can anyone point me to a sample or example that will just load a set of UserXGroup combinations? If so, great. If not, I will try to write something myself and will post it here in case anyone else is interested.


Don Henderson

Lapis Lazuli | Level 10

After doing a little more research I found an example that reconciled the SAS metadata with an Active Directory structure. So I was able to modify it to do what I wanted. Basically the idea is to:

  1. Extract the metadata to a library
  2. Copy the metadata to a second library
  3. Update the data in the second library to incorporate the desired changes (in my case, the new User X Group combinations)
  4. Use the Compare macros to create the update rows
  5. Apply the updates.

For anyone who is interested, sample code follows:

/* Sample program to add user X group combinations to the metadata based on business

   logic to identify what existing users to add to what exiting groups.

   Based on the sample documented at:


options metaserver=SERVER-NAME







libname current '\temp';   /* for the current metadata */

libname addgrps '\temp2'/* current augmented with the changes */

libname updates '\temp3'/* for the updates created by the mducmp macro */


proc copy in = current out = addgrps;

/* just copy the current data to the directory for the target */


data users;

/* sample data - I created a couple of users to test with */

set current.person(keep=objid);

where objid in ('A5X4WGB2.AN0000S5' 'A5X4WGB2.AN0000S6');

rename objid = memkeyid;


data groups;

/* sample data - I created a couple of groups to test with */

set current.group_info(keep=id);

where id in ('A5X4WGB2.A30000S0' 'A5X4WGB2.A30000S1');

rename id = grpkeyid;


proc sql;

/* create a cartesian product to add the two users to the two groups.

    subsetting logic can be added to specify was users are to be added to what groups


create table grpmems as

select * from users, groups;


proc append base = addgrps.grpmems data = grpmems;

/* augment the target data with the new user X group combinations */


/* use the mducmp macro to create the updates data - it should just be the new

   user X group combinations


%mducmp(master=addgrps, target=current, change=updates)

/* validate the change data sets */

%mduchgv(change=updates, target=current, temp=work, errorsds=work.mduchgverrors)

/* apply the updates */


Fluorite | Level 6

Thank You.

Barite | Level 11

Another approach:


/* load the MacroCore library */
filename mc url ""; %inc mc;

/* add a user to a group */
%mm_adduser2group(user=sasdemo, group=someGroup)



SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs



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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1 like
  • 3 in conversation