Frage

I am writing a deployment script, and would like to programmatically register a simple (and empty) BASE library, such as the one below, in Metadata.

libname MYLIB 'C:\temp';

Sample XML syntax can be found here.. Am just not sure how to combine that with proc metadata to perform the update (eg how do the metadata ID's get generated?)

War es hilfreich?

Lösung

@user2173800 Did u ever recieve a solution to the question above? Here is what i came up with :

The below Code creates a SAS Library called BASE_Metalib under the Metadata folder :/Shared Data/Libraries/BASE_Metalib (this folder is assumed to already exist in Metadata). The code also resgisters all tables under this Directory defined for this Library. The below code uses Metadata Datastep functions to Interface with metadata.

/*Creating a Metadata Library with BASE Engine and register all the tables under it */


options metaserver="taasasf2"
        metaport=8561
        metauser="testuser" 
        metapass="test123"
        metarepository="Foundation";

%Let MetaLibName=BASE_Metalib; /* Name of the SAS Library with BASE Engine to be created */


data _null_;
    length luri uri muri $256;


    rc=0;

    Call missing(luri,uri,muri);

    /* Create a SASLibrary object in the Shared Data folder. */

    rc=metadata_newobj("SASLibrary",
                       luri,
                       "&MetaLibname.",
                        "Foundation",
                        "omsobj:Tree?@Name=%bquote('&Metalibname.')",
                        "Members");
    put rc=;
    put luri=;

    /* Add PublicType,UsageVersion,Engine,Libref,IsDBMSLibname attribute values. */

        rc=metadata_setattr(luri, 
                            "PublicType",
                            "Library");
        put rc=;
        put luri=;

        rc=metadata_setattr(luri, 
                            "UsageVersion",
                            "1000000.0");
        put rc=;
        put luri=;

        rc=metadata_setattr(luri, 
                            "Engine",
                            "BASE");
        put rc=;
        put luri=;

        rc=metadata_setattr(luri, 
                            "Libref",
                            "SASTEST");
        put rc=;
        put luri=;

        rc=metadata_setattr(luri, 
                            "IsDBMSLibname",
                            "0");
        put rc=;
        put luri=;


/* Set Directory Object via UsingPackages Association for the SAS Library Object */

           rc=metadata_newobj("Directory",
                       uri,
                       "");
         put uri=;



        rc=metadata_setassn(luri,
                        "UsingPackages",
                        "Replace",
                        uri);
       put rc=;

       rc=metadata_setattr(uri,"DirectoryName","/shrproj/files/ANA_AR2_UWCRQ/data");

       put rc=;

/* Set Server Context Object via DeployedComponents Association for the SAS Library Object */


   rc=metadata_getnobj("omsobj:ServerContext?@Name='SASApp'",1,muri);

      put muri=;

      rc=metadata_setassn(luri,
                        "DeployedComponents",
                        "Append",
                        muri);

      put rc=;

Run;



proc metalib;
     omr (library="&Metalibname.");
     report;
run;

Andere Tipps

I finally got around to this - there are a few things to consider!

1) Making sure all the necessary objects exist (to avoid orphan metadata data)

2) Checking to ensure that objects are successfully created

3) Checking to avoid creating the library twice (idempotence)

4) General preference to avoid data step metadata functions and the corresponding risk of infinite loops

The XML part of the program looks like this:

/**
* Prepare the XML and create the library
*/
data _null_;
  file &frefin;
  treeuri=quote(symget('treeuri'));
  serveruri=quote(symget('serveruri'));
  directoryuri=quote(symget('directoryuri'));
  libname=quote(symget('libname'));
  libref=quote(symget('libref'));
  IsPreassigned=quote(symget('IsPreassigned'));
  prototypeuri=quote(symget('prototypeuri'));

  /* escape description so it can be stored as XML */
  libdesc=tranwrd(symget('libdesc'),'&','&');
  libdesc=tranwrd(libdesc,'<','&lt;');
  libdesc=tranwrd(libdesc,'>','&gt;');
  libdesc=tranwrd(libdesc,"'",'&apos;');
  libdesc=tranwrd(libdesc,'"','&quot;');
  libdesc=tranwrd(libdesc,'0A'x,'&#10;');
  libdesc=tranwrd(libdesc,'0D'x,'&#13;');
  libdesc=quote(trim(libdesc));

  put "<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata> "/
      '<SASLibrary Desc=' libdesc ' Engine="BASE" IsDBMSLibname="0" '/
      '  IsHidden="0" IsPreassigned=' IsPreassigned ' Libref=' libref /
      '  UsageVersion="1000000" PublicType="Library" name=' libname '>'/
      '  <DeployedComponents>'/
      '    <ServerContext ObjRef=' serveruri "/>"/
      '  </DeployedComponents>'/
      '  <PropertySets>'/
      '    <PropertySet Name="ModifiedByProductPropertySet" '/
      '      SetRole="ModifiedByProductPropertySet" UsageVersion="0" />'/
      '  </PropertySets>'/
      "  <Trees><Tree ObjRef=" treeuri "/></Trees>"/
      '  <UsingPackages> '/
      '    <Directory ObjRef=' directoryuri ' />'/
      '  </UsingPackages>'/
      '  <UsingPrototype>'/
      '    <Prototype ObjRef=' prototypeuri '/>'/
      '  </UsingPrototype>'/
      '</SASLibrary></Metadata><NS>SAS</NS>'/
      '<Flags>268435456</Flags></AddMetadata>';
  run;

For full code, check out the github repo.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top