Presentation is loading. Please wait.

Presentation is loading. Please wait.

Getting your metadata using PROC METADATA

Similar presentations


Presentation on theme: "Getting your metadata using PROC METADATA"— Presentation transcript:

1 Getting your metadata using PROC METADATA
Edwin J. van Stein Astellas Pharma Global Development Europe Copyright © 2005, SAS Institute Inc. All rights reserved.

2 Contents Example of using PROC METADATA to get group memberships for a specific user from metadata Due to time constraints I will not be able to explain every option in PROC METADATA. I will give an example of how to get group memberships for a specific user using things like a template and an XMLSelect element to filter on. Some easier examples and explanations about options and server connection arguments are given in the full paper. The full paper also has some information on converting the resulting XML file to SAS data sets.

3 Preparing for output Output written to physical XML file to later convert to SAS data set Encoding of XML file specified to prevent problems with strange characters filename outgroups "/sas/user/test/groups.xml" encoding="utf-8"; If no output destination is specified in PROC METADATA then the output is written to the log. Since we want to process it later on we define a file reference to write the output to. This can also be a temporary file reference. I’ve had problems with encoding of strange characters between Windows and Unix so defining encoding is advisable when working on different operating systems.

4 Setting server connection arguments
SERVER, PORT, USER, PASSWORD and PROTOCOL all default to corresponding system options if not specified USER and PASSWORD (encoded with PROC PWENCODE) set to user with more rights proc metadata userid="sasadm" password="{sas001}bXkgcGFzc3dvcmQ=" The server connection arguments that can be used in PROC METADATA all default to system options, so if these are set properly you normally do not need to specify them in your PROC METADATA call. An exception can be USER and PASSWORD since these define what you can see. If you need to see data that your normal login does not have access to you can specify another user and password. Password can be encoded using PROC PWENCODE and it’s a good idea to take other precautions like limiting what ends up in the logs.

5 Setting output arguments
Write output to file reference created earlier Output XML to contain a full header out=outgroups header=full We want the output to be written to the file reference we’ve created earlier. Again because of possible encoding issues the output XML should contain a full header so that the output XML contains an XML declaration that specifies the encoding used. If we want SAS to print the XML-formatted method call in the log we can add the VERBOSE output argument.

6 XML-formatted method call (1)
Tell the metadata server to get objects From which repository to get objects Type of objects to get Specify namespace in='<GetMetadataObjects> <Reposid>$METAREPOSITORY</Reposid> <Type>Person</Type> <NS>SAS</NS> The XML-formatted method call are the instructions sent to the metadata server formatted as XML. Because persons and identitygroups are objects in metadata we need to tell the metadata server to get objects. <GetMetadataObjects> requires the repository to be defined. As long as the system option METAREPOSITORY is set you can use the sustitution variable $METAREPOSITORY. For a specific person we want to get group memberships, so type of object to get is Person (then within person we will get all group memberships). <GetMetadataObjects> requires the namespace to be defined. This can be either REPOS (types that describe repositories) or SAS (types that describe application elements, which includes tables, columns, users, groups, folders, stored processes, etc.). In case of doubt just try the 2 options available.

7 XML-formatted method call (2)
Set flags so that metadata server performs the correct actions: Fill a pre-specified template (flag OMI_TEMPLATE=4) Use an XMLSelect element to filter metadata (flag OMI_XMLSELECT=128) Get the metadata found (flag OMI_GET_METADATA=256) Use XMLSelect element case-sensitive (flag OMI_MATCH_CASE=512) <Flags>900</Flags> The XML-formatted method call uses flags to tell the metadata server what to do with the instructions received. These flags are described in the documentation on the Open Metadata Interface. In this example we want a pre-specified template to be filled so that we only get the variables we’re interested in. We will be supplying an XMLSelect element to filter the data so that we only get the records we’re interested in. The metadata server needs to return the metadata found. And the XMLSelect element is case-sensitive (default is case insensitive).

8 XML-formatted method call (3)
Both template and XMLSelect element need to be within <Options> tags Only want person and group names returned <Options> <Templates> <Person Name=""> <IdentityGroups /> </Person> <IdentityGroup Name=""/> </Templates> Both the template and the XMLSelect element need to be within <Options> tags. In the template we specify that for Person we want to get Name and within Person the IdentityGroups and of those groups the Name. There are multiple ways of structuring the template. For instance you could also remove the frontslash in the IdentityGroups tag and put the IdentityGroup tag after it and then add a closing IdentityGroups tag.

9 XML-formatted method call (4)
Only return data for persons with a specific name Close open tags to finalize XML-formatted method call <XMLSelect 1''"/> </Options> </GetMetadataObjects>' Since we only want to get the data for a specific person the XMLSelect element is set to search for objects with the name attribute set to a specific string (case sensitive because of the flag set earlier. There were still some tags to close, so that’s also done here.

10 Putting it all together
proc metadata userid="sasadm" password="{sas001}bXkgcGFzc3dvcmQ=" out=outgroups header=full in='<GetMetadataObjects> <Reposid>$METAREPOSITORY</Reposid> <Type>Person</Type> <NS>SAS</NS> <Flags>900</Flags> <Options> <Templates> <Person Name=""> <IdentityGroups /> </Person> <IdentityGroup Name=""/> </Templates> <XMLSelect 1''"/> </Options> </GetMetadataObjects>'; run; Combining all of the above you get this proc metadata call.

11 The XML output (partial)
When the PROC METADATA from the previous slide is run an XML file is created with all the metadata returned and some information on what was done. The output XML when opened in a web browser will look something like this.

12 Next steps Explore metadata using 257 as Flag and only setting Type
Conversion to data set using an XML map Update metadata When you don’t know exactly what attributes are available for the objects you are interested in or want to know what children those objects have simply run PROC METADATA with 257 as flag and a type set to get all the data for those object types. Based on the output you can then create an XMLSelect element and template. This xml file can be converted into a SAS data set using an XML map, but that’s out of the scope of this presentation (some examples and tips are given in the paper). PROC METADATA can also be used to add, update and delete metadata with tags like AddMetadata, DeleteMetadata and UpdateMetadata instead of GetMetadataObjects. This can seriously mess up your metadata though so only do this if you really know what you’re doing.

13 Questions nl.linkedin.com/in/ejvanstein


Download ppt "Getting your metadata using PROC METADATA"

Similar presentations


Ads by Google