SAS,以编程方式导出元数据对象spks

时间:2015-08-25 14:05:59

标签: sas sas-metadata

在SAS中,我有一个包含大量SAS表元数据的文件夹结构。

要从一个环境迁移到另一个环境,我们需要手动创建大量的spk并将它们推送到Git。这是有问题的,因为它(a)需要时间,(b)开发人员被激励将大量元数据对象打包到一个.spk中,这会产生问题,当只需要编辑其中一个对象时,没有人可以编辑被审查。

有吗:

  1. 以编程方式导出.spk文件的方法吗?
  2. 解析文件夹结构并为每个元数据对象创建一个spk文件的方法吗?
  3. 如果你能指出我有用的SAS论文或指出我正确的方向,那就太好了。

1 个答案:

答案 0 :(得分:3)

您的方法有两点需要指出:

  1. 由于嵌入的时间戳,导出两次时,相同的元数据项将具有不同的校验和。这将始终在GIT中产生差异。
  2. 单独导出每个元数据项需要很长时间 - ExportPackage例程并不快。
  3. 但无论如何,你提出的建议当然可以做到!我刚刚测试了下面,它工作正常。如果您不在Windows上,则可能需要调整管道中ExportPackage实用程序的路径(使用分号 - ; - 链接命令)..

    %macro exporter(root=%sysfunc(pathname(work)) /* physical root */
        ,host=dev-meta.ACME.int /* metadata server */
        ,port=8561              /* metadata port */
        ,user=sasdemo           /* user with metadata credentials */
        ,pass=Mars123           /* password */
      );
    options noquotelenmax;
    
    data paths (keep=tree_path uri treetype);
      length tree_path $500 uri tree_uri parent_uri 
        parent_name TreeType PublicType $256;
      n=1;
      do while(metadata_getnobj("omsobj:Tree?@PublicType = 'Folder'",n,uri)>0);
      /* code for getting the metadata path */
        rc=metadata_getattr(uri,"Name",tree_path);
        rc=metadata_getattr(uri,"TreeType",TreeType);
        rc=metadata_getattr(uri,"PublicType",PublicType);
        tree_uri=uri;
        do while (metadata_getnasn(tree_uri,"ParentTree",1,parent_uri)>0);
          rc=metadata_getattr(parent_uri,"Name",parent_name);
          tree_path=strip(parent_name)||'/'||strip(tree_path);
          tree_uri=parent_uri;
        end;
        tree_path='/'||strip(tree_path);
        call symputx(cats('path',n),tree_path,'l');
        call symputx(cats('uri',n),uri,'l');
        call symputx('n',n,'l');
        output;
        n+1;
        if n>3 then leave;  /* remove this unless testing */
      end;
    run;
    proc sort; by tree_path;run;
    
    /* get location of BatchExport metadata tool */
    /*http://support.sas.com/documentation/cdl/en/bisag/64088
         /HTML/default/viewer.htm#a003261084.htm*/
    data _null_;
       h="%sysget(SASROOT)";
       h2=substr(h,1,index(h,"SASFoundation")-2);
       call symputx("platform_object_path"
        ,cats(h2,"/SASPlatformObjectFramework/&sysver"));
    run;
    %put Batch tool located at: &platform_object_path;
    
    %let connx_string= -host &host -port &port -user &user -password &pass;
    
    %do x=1 %to &n;
      data out&x (drop=n rc);
        length uri objuri Name PublicType path $256;
        retain path "&&path&x";
        retain uri "&&uri&x";
        n=1;
        do while (metadata_getnasn(uri,'Members',n,objuri)>0);
          rc=metadata_getattr(objuri,"Name",Name);
          rc=metadata_getattr(objuri,"PublicType",PublicType);
          call symputx(cats('objuri',n),objuri,'l');
          call symputx(cats('objName',n),Name,'l');
          call symputx(cats('objType',n),PublicType,'l');
          output;
          n+1;
        end;
      run;
      proc sql noprint;
      select count(*) into: nobs from &syslast;
      %if &nobs=0 %then %do;
        drop table &syslast;
      %end;
      %else %do objn=1 %to &nobs;
        data _null_;
          infile "C: & cd ""&platform_object_path"" %trim(
            ) & ExportPackage &connx_string %trim(
            )-package ""&root&&path&x\&&objType&objn.._&&objname&objn...spk"" %trim(
            )-objects ""&&path&x/&&objname&objn(&&objType&objn)"" %trim(
            )-log ""&root&&path&x\&&objType&objn.._&&objname&objn...log"" 2>&1" 
            pipe lrecl=1000;
          input; 
          list;
        run;
      %end;
    %end;
    %mend;
    
    %exporter()