Architecting, installing and maintaining your SAS environment

Querying the metadata for a list of users and groups

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Querying the metadata for a list of users and groups

Hi, first of all, I'm not a SAS VA administrator. I'm a software developer with background in different databases and languages. We have been using SAS VA for a while, but the person that set it up is not longer with us. I've been doing the administration through the SAS Management Console so far with no problem. Now I've been asked to produce a report with all users and groups they belong to. So, I started digging around to see if that was possible. I thought I could do it login directly the underlying database (mysql?) or through the application creating a new report that would pull from users and groups instead of the data we are using for other reports. The problem is that I can't find where users and groups are stored. I checked several answers in this forums and they did not made sense to me (remember, I'm new to this tool). Can I get some help on where should I look?

 

Thanks,

 

Marc


Accepted Solutions
Solution
‎08-30-2017 04:32 PM
SAS Employee
Posts: 316

Re: Querying the metadata for a list of users and groups

Posted in reply to marccarrion

@marccarrion,

 

This SAS program produces a list of users and groups in the metadata with the date they were added. Just run this program in SAS Studio or EG:

 

data users_grps; 
  
/* The LENGTH statement defines variables for function arguments and 
assigns the maximum length of each variable.  */   
  
  length uri name dispname group groupuri $256 
id MDUpdate $20; 
  
/* The CALL MISSING routine initializes output variables to missing values.*/ 
  
  n=1; 
      call missing(uri, name, dispname, group, groupuri, id, MDUpdate); 
  
     
  /* The METADATA_GETNOBJ function specifies to get the Person objects 
in the repository. The n argument specifies to get the first Person object that is 
returned. The uri argument will return the actual uri of the Person object that 
is returned. The program prints an informational message if no Person objects 
are found. */ 
  
      nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri); 
  if nobj=0 then put 'No Persons available.'; 
  
/* The DO statement specifies a group of statements to be executed as a unit 
for the Person object that is returned by METADATA_GETNOBJ. The METADATA_GETATTR 
function gets the values of the object's Name and DisplayName attributes. */ 
  
  else do while (nobj > 0); 
     rc=metadata_getattr(uri, "Name", Name); 
     rc=metadata_getattr(uri, "DisplayName", DispName); 
  
  
/* The METADATA_GETNASN function gets objects associated via the IdentityGroups 
association. The a argument specifies to return the first associated object for 
that association type. The URI of the associated object is returned in the 
groupuri variable.  */ 
  
   a=1; 
     grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri); 
         
        /* If a person does not belong to any groups, set their group 
          variable to 'No groups' and output their name. */ 
  
     if grpassn in (-3,-4) then do; 
            group="No groups"; 
        output; 
     end; 
  
        /* If the person belongs to many groups, loop through the list 
          and retrieve the Name and MetadataUpdated attributes of each group, 
            outputting each on a separate record. */ 
  
     else do while (grpassn > 0); 
        rc2=metadata_getattr(groupuri, "Name", group); 
        rc=metadata_getattr(groupuri, "MetadataUpdated", MDUpdate); 
        a+1; 
        output; 
        grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri); 
     end; 
        
       /* Retrieve the next person's information */ 
  
     n+1; 
     nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri); 
  end; 
  
/* The KEEP statement specifies the variables to include in the output data set. */ 
  
  keep name dispname MDUpdate group; 
run; 
  
   /* Display the list of users and their groups */ 
proc report data=users_grps nowd headline headskip; 
  columns name dispname group MDUpdate; 
  define name / order 'User Name' format=$30.; 
  define dispname / order 'Display Name' format=$30.; 
  define group / order 'Group' format=$30.; 
  define MDUpdate / display 'Updated' format=$20.; 
  break after name / skip; 
run; 

View solution in original post


All Replies
Solution
‎08-30-2017 04:32 PM
SAS Employee
Posts: 316

Re: Querying the metadata for a list of users and groups

Posted in reply to marccarrion

@marccarrion,

 

This SAS program produces a list of users and groups in the metadata with the date they were added. Just run this program in SAS Studio or EG:

 

data users_grps; 
  
/* The LENGTH statement defines variables for function arguments and 
assigns the maximum length of each variable.  */   
  
  length uri name dispname group groupuri $256 
id MDUpdate $20; 
  
/* The CALL MISSING routine initializes output variables to missing values.*/ 
  
  n=1; 
      call missing(uri, name, dispname, group, groupuri, id, MDUpdate); 
  
     
  /* The METADATA_GETNOBJ function specifies to get the Person objects 
in the repository. The n argument specifies to get the first Person object that is 
returned. The uri argument will return the actual uri of the Person object that 
is returned. The program prints an informational message if no Person objects 
are found. */ 
  
      nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri); 
  if nobj=0 then put 'No Persons available.'; 
  
/* The DO statement specifies a group of statements to be executed as a unit 
for the Person object that is returned by METADATA_GETNOBJ. The METADATA_GETATTR 
function gets the values of the object's Name and DisplayName attributes. */ 
  
  else do while (nobj > 0); 
     rc=metadata_getattr(uri, "Name", Name); 
     rc=metadata_getattr(uri, "DisplayName", DispName); 
  
  
/* The METADATA_GETNASN function gets objects associated via the IdentityGroups 
association. The a argument specifies to return the first associated object for 
that association type. The URI of the associated object is returned in the 
groupuri variable.  */ 
  
   a=1; 
     grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri); 
         
        /* If a person does not belong to any groups, set their group 
          variable to 'No groups' and output their name. */ 
  
     if grpassn in (-3,-4) then do; 
            group="No groups"; 
        output; 
     end; 
  
        /* If the person belongs to many groups, loop through the list 
          and retrieve the Name and MetadataUpdated attributes of each group, 
            outputting each on a separate record. */ 
  
     else do while (grpassn > 0); 
        rc2=metadata_getattr(groupuri, "Name", group); 
        rc=metadata_getattr(groupuri, "MetadataUpdated", MDUpdate); 
        a+1; 
        output; 
        grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri); 
     end; 
        
       /* Retrieve the next person's information */ 
  
     n+1; 
     nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri); 
  end; 
  
/* The KEEP statement specifies the variables to include in the output data set. */ 
  
  keep name dispname MDUpdate group; 
run; 
  
   /* Display the list of users and their groups */ 
proc report data=users_grps nowd headline headskip; 
  columns name dispname group MDUpdate; 
  define name / order 'User Name' format=$30.; 
  define dispname / order 'Display Name' format=$30.; 
  define group / order 'Group' format=$30.; 
  define MDUpdate / display 'Updated' format=$20.; 
  break after name / skip; 
run; 
New Contributor
Posts: 2

Re: Querying the metadata for a list of users and groups

Thanks Alexal, this was my first time using EG, and it worked great, just as you said. I'm going to check with my users to see what else they want on the report, but this gives me a great starting point. Thanks!!

 

Marc

SAS Employee
Posts: 316

Re: Querying the metadata for a list of users and groups

Posted in reply to marccarrion

@marccarrion,

 

You are welcome!

Moderator
Posts: 252

Re: Querying the metadata for a list of users and groups

Posted in reply to marccarrion

If you have Extended Monitoring turned on, the user/group report is one of a myriad of automated reports available through the Stored Process Web Server.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 219 views
  • 2 likes
  • 3 in conversation