BookmarkSubscribeRSS Feed
Ddolic
Calcite | Level 5
Dear Community.

I try to query a Metadatarepository and bring the result in a dataset so that there will be three columns: The SAS-Name of all Tables, the corresponding ID and the Tree Name where the table resides. I am as far as knowing how to query the information. I try to put them into a template, but that seem to be the tricky part.

Working so far:
data _null_;
file query;
input;
put _infile_;
datalines;

$METAREPOSITORY
PhysicalTable

SAS
261







;;
run;

%procmeta(out=rawdata)

%procmeta only does the PROC METADATA and has all the credential and repository stuff. the out is only for control reasons there.

Now I try to put the results from the Stuff into a dataset. Here we go:

data _null_;
file map;
input;
put _infile_;
datalines;









/GetMetadataObjects/Objects/PhysicalTable

/GetMetadataObjects/Objects/PhysicalTable/Trees/@Name
character
string
17


/GetMetadataObjects/Objects/PhysicalTable/@Id
character
string
17


/GetMetadataObjects/Objects/PhysicalTable/@Name
character
string
40




/GetMetadataObjects

/GetMetadataObjects/Reposid
character
string
17



;
run;


data tmp;
set myxml.Tableinfo ;
run;

I tried several variations of the column definitions and even of the Stuff. either I get the Information on all trees or I get the information on all tables. But I need both in one table. As there are perfectly existing in the output from GetMetadata there has to be a way to get them into the dataset.
Any hints, where I'm wrong?

Thanks

Dubro
1 REPLY 1
DanielSantos
Barite | Level 11
Hi,
you should query both objects (PhysicalTable and Tree) and match them by either TreeID or TableID.

Here's an example, that will query all tables (and their tree associations) and trees and match the two.
[pre]
%let REPID=XXXXXXXXXXXX; * REPLACE WITH THE DESIRED REP ID!!!!;

filename request temp lrecl=2048;

* maps;
filename x_tabs_m temp lrecl=2048;
data _null_;
file x_tabs_m encoding="UTF-8";
put '';
put '';
put '';
put '/GetMetadataObjects/Objects/PhysicalTable';
put 'characterSTRING50/GetMetadataObjects/Objects/PhysicalTable@Id';
put 'characterSTRING200/GetMetadataObjects/Objects/PhysicalTable@Name';
put 'characterSTRING50/GetMetadataObjects/Objects/PhysicalTable/Trees/Tree@Id';
put '
';
put '
';
run;
filename x_trees_m temp lrecl=2048;
data _null_;
file x_trees_m encoding="UTF-8";
put '';
put '';
put '';
put '/GetMetadataObjects/Objects/Tree';
put 'characterSTRING50/GetMetadataObjects/Objects/Tree@Id';
put 'characterSTRING200/GetMetadataObjects/Objects/Tree@Name';
put '
';
put '
';
run;

* queries;
filename x_tabs temp lrecl=800000;
data _null_;
file request;
put '';
put "&REPID";
put 'PhysicalTable';
put '';
put 'SAS';
put '276';
put '';
put '';
put '';
put '
';
put '
';
put '
';
run;
proc metadata in=request out=x_tabs;
run;

filename x_trees temp lrecl=800000;
data _null_;
file request;
put '';
put "&REPID";
put 'Tree';
put '';
put 'SAS';
put '276';
put '';
put '';
put '
';
put '
';
run;
proc metadata in=request out=x_trees;
run;

* extract desired metadata;
libname x_tabs xml xmlmap=x_tabs_m;
libname x_trees xml xmlmap=x_trees_m;
proc sql;
select T1.TabName, T1.TabId, T2.TreeName, T2.TreeId
from x_tabs.x_tabs as T1 left outer join x_trees.x_trees as T2
on T1.TreeID = T2.TreeId;
run;
[/pre]
Cheers from Portugal.

Daniel Santos @ www.cgd.pt

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 611 views
  • 0 likes
  • 2 in conversation