SAS, programmatically export metadata object objects

In SAS, I have a folder structure that contains a lot of SAS table metadata.

To move from one environment to another, we need to manually create a large number of spks and click them on Git. This is problematic because it (a) takes time, (b) developers are interested in packing a large number of metadata objects in one .spk, which creates problems in the line when only one of these objects needs to be edited, and no one can to reconsider.

Whether there is a:

  • How to programmatically export a .spk file?
  • How to analyze folder structure and create one spk file for each metadata object?

It would be great if you could point me to useful SAS papers or point me in the right direction.

+6
source share
1 answer

There are two things in your approach:

  • The same metadata element will have different checksums when exporting twice due to the built-in timestamps. This will always create differences in GIT.
  • Exporting each metadata item individually will take a long time - the ExportPackage procedure is not so fast.

But in any case, of course, what you offer can be done! I just tested below and it works great. If you are not in windows, you may have to adjust the path to the ExportPackage utility in the pipe (using the semicolon commands ExportPackage - chain).

 %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() 
+3
source

All Articles