I asked the following question on SAS Professionals so if you've seen it there please disregard.
I'm trying to write some code, using the metadata data step functions, which will query specified identities metadata. Where an identity is a group, I then want it to get the members of that group, and then do that recursively until it is down to persons only. I can't think of a way of writing recursive code in a data step so I thought I'd try using macro code. However, the metadata functions don't seem to work with %sysfunc. This is demonstrated by this log extract:
15 %let rc=%sysfunc(metadata_getattr(&identuri,Name,ident_name));
16 %put identuri=&identuri rc=&rc ident_name=&ident_name;
WARNING: Apparent symbolic reference IDENT_NAME not resolved.
identuri=OMSOBJ:IdentityGroup\A54UQ8A9.A300005Q rc=0 ident_name=&ident_name
The ident_name macro variable never gets defined because it's not the function's return code, but one of the function's arguments.
Can anyone suggest a way around this, or an alternative method? I don't know if it would be possible with PROC METADATA. I've never really got to grips with the XML for querying the metadata.
Thanks
How about this:
Write a data step that works through a dataset containing metadata objects and expands all objects of type "group" into their members. At the end, the data step should use call symput to create a macro variable that signals if any "group" type records were found.
Then use a macro that repeats that datastep with a %do %while loop until the dataset has been stripped of all "group" records.
%macro do_it;
%let signal = 1;
%do %while &signal = 1;
data dataset (drop=signal);
set dataset end=done;
retain signal 0;
if type = "group"
then do;
/* get members and write a record for each */
signal = 1;
end;
else output;
if done then call symput('signal',put(signal,1.));
run;
%end;
%mend;
How about this:
Write a data step that works through a dataset containing metadata objects and expands all objects of type "group" into their members. At the end, the data step should use call symput to create a macro variable that signals if any "group" type records were found.
Then use a macro that repeats that datastep with a %do %while loop until the dataset has been stripped of all "group" records.
%macro do_it;
%let signal = 1;
%do %while &signal = 1;
data dataset (drop=signal);
set dataset end=done;
retain signal 0;
if type = "group"
then do;
/* get members and write a record for each */
signal = 1;
end;
else output;
if done then call symput('signal',put(signal,1.));
run;
%end;
%mend;
Thanks Kurt, that looks like a method I can work with. Trust me to try and get too complicated.
Hi Nigel
You could package the METADATA_... functions using Proc FCMP. This way it is possible to call your function from %SYSFUNC.
Find below a code sample that shows this.
Thanks Bruno. I've never used PROC FCMP before. I'll have to have a read up on it.
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.
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.