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
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:
*/
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)
Thank You.
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
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.
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.