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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

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 🙂

 

View solution in original post

9 REPLIES 9
SASKiwi
PROC Star

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.  

Tom2021
Fluorite | Level 6
Thank you SASkivi for your good advice. Coding with metadata is very complicated. This only asks two input values, maybe some simple code is available. I already have macro code to add user into groups from sas. Now I was testing approach in sas bulkload sample code to create new user, coding is easier, but failed to setup defaultauth. I will further test it...thanks...
andreas_lds
Jade | Level 19

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 🙂

 

Tom2021
Fluorite | Level 6

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

Tom2021
Fluorite | Level 6

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.

Tom2021
Fluorite | Level 6

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!

Tom2021
Fluorite | Level 6

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;

 

Patrick
Opal | Level 21

@Tom2021 

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.

Tom2021
Fluorite | Level 6

thank you @Patrick. The service is good. Currently we do not have complex tasks for the service. Thanks

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 9 replies
  • 1382 views
  • 4 likes
  • 4 in conversation