07-14-2013 03:38 PM
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.
07-14-2013 05:58 PM
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:
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:
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 */
/* sample data - I created a couple of users to test with */
where objid in ('A5X4WGB2.AN0000S5' 'A5X4WGB2.AN0000S6');
rename objid = memkeyid;
/* sample data - I created a couple of groups to test with */
where id in ('A5X4WGB2.A30000S0' 'A5X4WGB2.A30000S1');
rename id = grpkeyid;
/* 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 */