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)) ,host=dev-meta.ACME.int ,port=8561 ,user=sasdemo ,pass=Mars123 ); 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); 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; end; run; proc sort; by tree_path;run; 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()