Could you provide advice and sample code?
I want to create a sas macro like %macro m_createoneuser(username, loginid) to create a new user account with 2 input values: one user name, the user login id only to be called in base sas command line to integrate into Automation of Ansible. The loginid will be in DefaultAuth. Do not use sas management console to create user in GUI; do not import information from active directory or unix or ldap system. thanks.
I can't post full code, contains lots of things not necessary to solve your problem.
Step 1 Get the URI of DefaultAuth:
rc = metadata_getnobj("omsobj:AuthenticationDomain?AuthenticationDomain[@Name = 'DefaultAuth']", 1, UriDefaultAuth);
rc should be exactly 1
Step 2 Create person, assuming that username is unique, if it is not replacing it with loginid is recommended.
rc = metadata_newobj('Person', UriPerson, "&username");
Step 3 Setting some attributes, i am using the value for UsageVersion for some time, you can check the value using metabrowse in display manager or by using metadata_getattr on a user created with sas management console.
rc = metadata_setattr(UriPerson, 'PublicType', 'User');
rc = metadata_setattr(UriPerson, 'UsageVersion', '1000000');
Step 4 The Login-object
call missing(UriLogin);
/* not sure, if you need to use username or loginid in the next line */
rc = metadata_newobj("Login", UriLogin, "Login.&username", 'Foundation', UriPerson, "Logins");
rc = metadata_setattr(UriLogin, "UserID", "&loginID.");
rc = metadata_setassn(UriLogin, 'Domain', 'Append', UriDefaultAuth);
Having a recent backup the metadata is highly recommended 🙂
Doing what you ask involves using the DATA step interface to SAS metadata. It means becoming familiar with SAS's metadata data model as well as the many functions in the DATA step interface. The coding is highly complex and comes with the added danger of corrupting your SAS metadata repository. I suggest you take the time to explore the documentation, particularly the code examples, as that will give you a good understanding of what is required.
Also what Groups and Roles will you allocate to the new user? Without these the new user won't be able to do anything.
Personally I think synchronising SAS user metadata with external security data sources is a lot easier as Groups are set up automatically.
I can't post full code, contains lots of things not necessary to solve your problem.
Step 1 Get the URI of DefaultAuth:
rc = metadata_getnobj("omsobj:AuthenticationDomain?AuthenticationDomain[@Name = 'DefaultAuth']", 1, UriDefaultAuth);
rc should be exactly 1
Step 2 Create person, assuming that username is unique, if it is not replacing it with loginid is recommended.
rc = metadata_newobj('Person', UriPerson, "&username");
Step 3 Setting some attributes, i am using the value for UsageVersion for some time, you can check the value using metabrowse in display manager or by using metadata_getattr on a user created with sas management console.
rc = metadata_setattr(UriPerson, 'PublicType', 'User');
rc = metadata_setattr(UriPerson, 'UsageVersion', '1000000');
Step 4 The Login-object
call missing(UriLogin);
/* not sure, if you need to use username or loginid in the next line */
rc = metadata_newobj("Login", UriLogin, "Login.&username", 'Foundation', UriPerson, "Logins");
rc = metadata_setattr(UriLogin, "UserID", "&loginID.");
rc = metadata_setassn(UriLogin, 'Domain', 'Append', UriDefaultAuth);
Having a recent backup the metadata is highly recommended 🙂
thank you @andreas_lds , excellent! As input, username and loginid are all unique. We can setup username="first name lastname loginid". I will follow your instructions to try the approach...thanks
Hi, Andrea @andreas_lds I got error at step 2. after running, I can see the account was created but blank at tab accounts. no userid and DefaultAuth. could you help? thanks.
102 %mm_create_a_user(username8, loginid8);
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
102:124 102:92 102:152 102:156 102:189 102:35 102:78 102:152 102:228 102:12
NOTE: Variable UriDefaultAuth is uninitialized.
NOTE: Variable UriPerson is uninitialized.
HI, @andreas_lds I changed the line to
rc = metadata_getnobj("AuthenticationDomain?@Name='DefaultAuth'", 1, UriDefaultAuth);
failed at the line
rc = metadata_newobj("Login", UriLogin, "Login.&username", 'Foundation', UriPerson, "Logins");
The 2 Uri becomes blank. Could you help me? thanks!
Thank you @andreas_lds very much! Your sample code helped me and it is working properly now. Below is the full code. I will add error handling later. You know metadata functions very well. thanks again.
%macro mm_create_a_user(username, loginid);
data _null_;
length UriPerson UriDefaultAuth UriLogin $256;
call missing (UriPerson, UriDefaultAuth, UriLogin);
rc = metadata_getnobj("AuthenticationDomain?@Name='DefaultAuth'", 1, UriDefaultAuth);
rc = metadata_newobj('Person', UriPerson, "&username");
rc = metadata_setattr(UriPerson, 'PublicType', 'User');
rc = metadata_setattr(UriPerson, 'UsageVersion', '1000000');
rc = metadata_newobj("Login", UriLogin, "&loginid", 'Foundation', UriPerson,
rc = metadata_setattr(UriLogin, "UserID", "&loginid");
rc = metadata_setassn(UriLogin, 'Domain', 'Append', UriDefaultAuth);
run;
%mend mm_create_a_user;
If you really need to get into more complex tasks analyzing and especially changing metadata that significantly exceeds what comes already ootb then consider to investigate what Metacoda has to offer. I believe they also offer consulting services so depending on how big your company is and how stable and production-worthy things need to be, getting in contact with some real subject matter experts might be worth the time and cost.
NB: I only know about Metacoda's reputation but I won't profit in any way whatever you do so this is a honest recommendation without any hidden agenda.
thank you @Patrick. The service is good. Currently we do not have complex tasks for the service. Thanks
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.