Your SAS programs, embedded in web apps and elsewhere

Assigning existing users to existing metadata groups

Reply
Frequent Contributor
Posts: 148

Assigning existing users to existing metadata groups


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

Frequent Contributor
Posts: 148

Re: Assigning existing users to existing metadata groups

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)


Ask a Question
Discussion stats
  • 1 reply
  • 982 views
  • 0 likes
  • 1 in conversation