2

我正在编写一个部署脚本,并希望以编程方式在元数据中注册一个简单的(和空的)BASE 库,例如下面的那个。

libname MYLIB 'C:\temp';

可以在此处找到示例 XML 语法。我只是不确定如何将其与 proc 元数据结合以执行更新(例如,如何生成元数据 ID?)

4

2 回答 2

2

@user2173800 你有没有收到上述问题的解决方案?这是我想出的:

下面的代码在 Metadata 文件夹下创建了一个名为BASE_Metalib的 SAS 库: /Shared Data/Libraries/BASE_Metalib(假定此文件夹已存在于 Metadata 中)。该代码还重新注册了为此库定义的此目录下的所有表。下面的代码使用 Metadata Datastep 函数与元数据进行交互。

/*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;
于 2013-08-04T19:37:28.500 回答
0

我终于解决了这个问题 - 有几件事需要考虑!

1)确保所有必要的对象都存在(以避免孤立的元数据数据)

2) 检查以确保对象创建成功

3)检查以避免两次创建库(幂等性)

4) 一般偏好避免数据步元数据函数和相应的无限循环风险

程序的 XML 部分如下所示:

/**
* 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;

如需完整代码,请查看github 存储库

于 2018-08-14T22:26:59.093 回答