BookmarkSubscribeRSS Feed
DonH
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 importad.sas importpw.sas samples described in http://support.sas.com/kb/40/628.html). 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.

TIA,

Don Henderson

3 REPLIES 3
DonH
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:

   http://support.sas.com/documentation/cdl/en/bisecag/63082/HTML/default/viewer.htm#p0z36im6qsfk3ln1ad...

*/

options metaserver=SERVER-NAME

        metaport=8561

        metauser="XXXXXXXXXXXX"

        metapass="XXXXXXXXXXXX"

        metaprotocol=bridge

        metarepository=foundation;

                                  

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 */

%mduextr(libref=current);

proc copy in = current out = addgrps;

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

run;

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;

run;

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;

run;

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;

quit;

proc append base = addgrps.grpmems data = grpmems;

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

run;

/* 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 */

%mduchglb(change=updates)


ozg1969
Fluorite | Level 6

Thank You.

AllanBowe
Barite | Level 11

Another approach:

 

/* load the MacroCore library */
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas"; %inc mc;


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

 

Source:  https://github.com/sasjs/core/blob/main/meta/mm_adduser2group.sas

/Allan
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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