BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tom2021
Fluorite | Level 6

Hi, could some help me or provide some sample code? We want to use it in Ansible automation to automatically generate user account, instead of sas management console. thanks

%macro meta_create_user(username, login=, memberof=);

for example

%macro meta_create_user(testuserFN testuserLN, login=testuser1, memberof=testgroup1); or

%macro meta_create_user(testuserFN testuserLN, login=lestuser1, memberof=(testgroup1,testgroup2));

1 ACCEPTED SOLUTION

Accepted Solutions
AllanBowe
Barite | Level 11
To add a user to a group you can try this macro: https://core.sasjs.io/mm__adduser2group_8sas.html
/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

View solution in original post

15 REPLIES 15
Patrick
Opal | Level 21

@Tom2021 Before trying to write your own macro from scratch you might want to inspect what's already provided in the docu under User Import Macros.

Tom2021
Fluorite | Level 6

thanks Patrick, but, i tried %MDUCHGLB User Import Macro that cannot add user into existing group; all users and groups should be new from ad/unix/other external. they cannot have same names in metadata repository. i like to do more investigation. 

SASKiwi
PROC Star

@Tom2021  - Have you reviewed the whole process in @Patrick 's link? You need to run the macros that compare your external security data with SAS metadata, then only apply the changes that are found.

Tom2021
Fluorite | Level 6
thank you SASKivi, it is a full document. I read some and tried some. I will go further...thx
Tom2021
Fluorite | Level 6
thank you Patrick. This is a good direction. it is a full document. I will read it again and try to figure out testing plan to fit our custom need. thx
AllanBowe
Barite | Level 11
To add a user to a group you can try this macro: https://core.sasjs.io/mm__adduser2group_8sas.html
/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
Tom2021
Fluorite | Level 6
thank you Allan. i will try your codes. I have a concern. if it is working, I believe, Can we use some of your sas files? it is hard to develop so many professional macros as a full module.. thx
Tom2021
Fluorite | Level 6

Thank you Allan,

I read and tested your macro code. it is beautiful. it worked very well to add an existing user into specified groups. Could I use your macro file mm_adduser2group.sas?

My outstanding question or task is to create a macro to create a new user with user name and login id.

In the same time, I will try another approach suggested in the communication thread to use bulk load and sas macro %mduchgbl. Finally, I will choose the simpler one. 

Thank you again.

AllanBowe
Barite | Level 11
Yes of course- all the macros in the sasjs/core repo are MIT open source
and available for commercial use.

/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
Kurt_Bremser
Super User

In the examples directory of the SAS installation, you can find two programs (importpw.sas and importad.sas) that synchronize the metadata either with the UNIX passwd/group files or an Active Directory (LDAP) source. They manage everything (adding users/groups, add in users to existing groups, apply changes to existing users/groups, remove groups or users).

We have used both programs as blueprints for our sync needs, and they work perfectly.

Tom2021
Fluorite | Level 6
thank you Kurt. in our case, we do not need to import information from ad or unix; I will read the sas code and will try to modify it. thx
Kurt_Bremser
Super User

The programs consist of two parts: first extracting the user/group data from the source into a miniature database, and second creating a mirror base from the metadata, which is compared, resulting in a set of datasets for deleting, changing and adding metadata objects.

As long as you create the database correctly, the rest of the programs should work.

Tom2021
Fluorite | Level 6
I found the macro files written by Andrea Defronzo on github as the link; Tested, it is good, but I am not sure we can use the programs without copyright issue. At bottom, it calls sas metadata interface function. The coding is complicated with groups of sas macros. it is hard to learn and modify to create our codes. GitHub - andrewdef/sas_metadata_x_ansible: Ansible task to create SAS metadata objects (libraries, folders, etc.) in the Metadata Server
Ansible task to create SAS metadata objects (libraries, folders, etc.) in the Metadata Server
metautil_create_user.sas (%macro metautil_create_user(user_name, display_name=, login=, member_of=);). It calls these macros: metautil_parse_object_string.sas, metautil_create_object.sas
metautil_create_directory.sas, util_get_nobs.sas

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 15 replies
  • 2491 views
  • 1 like
  • 5 in conversation