2

I am new to the metadata concept and SAS DI. I need to query the foundation repository metadata and list out all the objects from it. Can someone please suggest how to achieve that? Thanks

Rhea
  • 283
  • 1
  • 5
  • 17

1 Answers1

3

Update - I wrote a macro lately that will download all objects from a metadata repository, so does exactly what you need.

/* compile macros*/
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc;

/* run code */
%mm_tree()

Full source code below.

* use a temporary fileref to hold the response;
filename response temp;
/* get list of libraries */
proc metadata in=
 '<GetMetadataObjects><Reposid>$METAREPOSITORY</Reposid>
   <Type>Tree</Type><Objects/><NS>SAS</NS>
   <Flags>384</Flags>
   <XMLSelect search="*[@TreeType=&apos;BIP Folder&apos;]"/>
   <Options/></GetMetadataObjects>'
  out=response;
run;
/*
data _null_;
  infile response;
  input;
  put _infile_;
  run;
*/

/* create an XML map to read the response */
filename sxlemap temp;
data _null_;
  file sxlemap;
  put '<SXLEMAP version="1.2" name="SASObjects"><TABLE name="SASObjects">';
  put "<TABLE-PATH syntax='XPath'>/GetMetadataObjects/Objects/Tree</TABLE-PATH>";
  put '<COLUMN name="pathuri">';
  put "<PATH syntax='XPath'>/GetMetadataObjects/Objects/Tree/@Id</PATH>";
  put "<TYPE>character</TYPE><DATATYPE>string</DATATYPE><LENGTH>64</LENGTH>";
  put '</COLUMN><COLUMN name="name">';
  put "<PATH syntax='XPath'>/GetMetadataObjects/Objects/Tree/@Name</PATH>";
  put "<TYPE>character</TYPE><DATATYPE>string</DATATYPE><LENGTH>256</LENGTH>";
  put '</COLUMN></TABLE></SXLEMAP>';
run;
libname _XML_ xml xmlfileref=response xmlmap=sxlemap;

data &outds;
  length metauri pathuri $64 name $256 path $1024
    publictype MetadataUpdated MetadataCreated $32;
  set _XML_.SASObjects;
  keep metauri name publictype MetadataUpdated MetadataCreated path;
  length parenturi pname $128 ;
  call missing(parenturi,pname);
  path=cats('/',name);
  /* get parents */
  tmpuri=pathuri;
  do while (metadata_getnasn(tmpuri,"ParentTree",1,parenturi)>0);
    rc=metadata_getattr(parenturi,"Name",pname);
    path=cats('/',pname,path);
    tmpuri=parenturi;
  end;
  
  if path=:"&root";

  %if "&types"="ALL" or ("&types" ne "ALL" and "&types" ne "Folder") %then %do;
    n=1;
    do while (metadata_getnasn(pathuri,"Members",n,metauri)>0);
      n+1;
      call missing(name,publictype,MetadataUpdated,MetadataCreated);
      rc=metadata_getattr(metauri,"Name", name);
      rc=metadata_getattr(metauri,"MetadataUpdated", MetadataUpdated);
      rc=metadata_getattr(metauri,"MetadataCreated", MetadataCreated);
      rc=metadata_getattr(metauri,"PublicType", PublicType);
    %if "&types" ne "ALL" %then %do;
      if publictype in (%mf_getquotedstr(&types)) then output;
    %end;
    %else output; ;
    end;
  %end;

  rc=metadata_resolve(pathuri,pname,tmpuri);
  metauri=cats('OMSOBJ:',pname,'\',pathuri);
  rc=metadata_getattr(metauri,"Name", name);
  rc=metadata_getattr(pathuri,"MetadataUpdated", MetadataUpdated);
  rc=metadata_getattr(pathuri,"MetadataCreated", MetadataCreated);
  rc=metadata_getattr(pathuri,"PublicType", PublicType);
  path=substr(path,1,length(path)-length(name)-1);
  if publictype ne '' then output;
run;
proc sort;
  by path;
run;
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
  • Thanks @Allan Bowe, I'm trying to understand your code files . The Code on the link by the name sas/stps/User/getTypes.sas - is it used to get a list of types of objects on the repo? since I tried to run that code on SAS EG and the output that I got did not make much sense to me. I basically need to get a list of tables, jobs, libraries and user transformation objects from the repo. – Rhea May 09 '19 at 04:19
  • Also, "3 - get attributes / associations / properties for a particular OBJECT" - could you please point me to the script help me how to get the details of the objects? – Rhea May 09 '19 at 06:06
  • The link points to the web services (SAS stps) that feed the Metadata Navigator app, so they'll need some small modifications to run in EG. Do you have access to the web server, and DI Studio or SMC? If so you could just deploy the app. The code above will anyway give you the list of Libraries, to get the other types just change the `type` macro variable and run it again.. – Allan Bowe May 09 '19 at 14:20
  • Thank you Allan, unfortunately I only have SAS EG. Could you help me how to get the details of all these objects, say how to get the details of all the SASLibrary Objects? – Rhea May 09 '19 at 23:06
  • I tried to lookup the getDetails code in your github link, but that seems to be setting a senduri dataset in the starting, which I don't know of, I tried to use the metadata Id instead but that fails too. I need to be able to fetch all the prperties available for all the objects. – Rhea May 10 '19 at 00:14
  • @Rhea - can you please ask a new question for that? The one you asked (get list of objects) has been answered – Allan Bowe May 10 '19 at 12:17
  • Sure Allan, I've asked a new question for that part. Posting the link here for completeness of the answer for anyone who might have the same query https://stackoverflow.com/questions/56083732/how-to-get-details-of-metadata-objects-in-sas – Rhea May 10 '19 at 19:27