0

Due to a requirement in creating multiple SAS libraries from time to time in the MC, I am trying to figure out how to do this programmatically. These libraries are pointing to external databases. So far, using the available examples I was able to use the following code to create library metadata.

proc metadata in='<AddMetadata>
 <Metadata>
   <SASLibrary
      Name="Test Library" 
      Desc="This is a test" 
      Folder="\Shared Data\Test"
      Engine="DB2"    
      IsDBMSLibname="1"      
      IsHidden="0"
      Libref="testlib"
      IsPreassigned="0"
      PublicType="Library">
    </SASLibrary>
 </Metadata>
 <Reposid>A0000001.A849HGWS</Reposid>
 <NS>SAS</NS>
 <Flags>268435456</Flags>
 <Options/>
</AddMetadata>
';

However this is still missing the resource template, schema name, location (folder name). Is there any way we can add these programmatically as well? Also anyway to update the access templates? Any attributes that I can assign these values to when calling proc metadata? Thanks in advance.

Sam
  • 850
  • 1
  • 10
  • 20
  • This macro could help, currently only supports BASE - pull requests are welcome if you can extend it https://core.sasjs.io/mm__createlibrary_8sas.html – Allan Bowe Nov 08 '22 at 15:17

2 Answers2

1

You can use the DATA Step function metadata_newobj("SASLibrary", to programmatically create your libraries. Check the documentation for "METADATA_NEWOBJ Function" for further examples of setting the attributes of the library via rc=metadata_setattr(luri,

Richard
  • 25,390
  • 3
  • 25
  • 38
0

Functions are ok but troublesome since you must invoke bunch of them to get desired result. XML as a template works best.

If you have access to SAS Management Console I am recommending enabling Metadata Inspector plugin.

cp -r $SASHOME/SASManagementConsole/9.4/plugins/advanced/omitoolsmc $SASHOME/SASManagementConsole/9.4/plugins/

Then in SASMC you are able to browse metadata of all objects using XML queries. Just go to Tools -> XML Metadata Interface.

Below is example XML fetched using this tool. To place this library in specific folder you need to know folder metadata id (Tree association). Same goes to associating library with a server context (DeployedComponents association) and/or DB2 server. Of course you need only necessary tags. You can ommit empty ones.

<SASLibrary Name="DB2 Library" Desc="Library description" Engine="DB2" IsDBMSLibname="1" IsHidden="0" IsPreassigned="0" Libref="DB2LIB" PublicType="Library">
    <AccessControls/>
    <Aliases/>
    <AliasFor/>
    <Changes/>
    <CustomAssociations/>
    <DefaultLogin/>
    <DeployedComponents>
        <ServerContext Id="associated context meta id" />
    </DeployedComponents>
    <Documents/>

    (...)

    <Timestamps/>
    <Trees>
        <Tree Id="folder meta id"/>
    </Trees>
    <TSObjectNamespace/>
    <UsedByPackages/>
    <UsedByPrototypes/>
    <UsingPackages/>
    <UsingPrototype/>
    <Variables/>
</SASLibrary>
fl0r3k
  • 619
  • 5
  • 9