DATA Step, Macro, Functions and more

Using data step functions to query identities in metadata

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

Using data step functions to query identities in metadata

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


Accepted Solutions
Solution
‎05-28-2015 06:40 AM
Super User
Posts: 7,809

Re: Using data step functions to query identities in metadata

Posted in reply to Nigel_Pain

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;

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎05-28-2015 06:40 AM
Super User
Posts: 7,809

Re: Using data step functions to query identities in metadata

Posted in reply to Nigel_Pain

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;

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 19

Re: Using data step functions to query identities in metadata

Posted in reply to KurtBremser

Thanks Kurt, that looks like a method I can work with. Trust me to try and get too complicated.

SAS Super FREQ
Posts: 708

Re: Using data step functions to query identities in metadata

Posted in reply to Nigel_Pain

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.


proc fcmp outlib=work.myfunctions.md;
  function md_getMembers(uri $)  $ 32767;
   
length
      returnList $
32767
      tempUri $
256
      memberName $
256
      memberType $
256
    ;
    n=1;
    nMem = metadata_getnasn(uri,
"MemberIdentities", n, tempURI);
    do i_mem = 1 to nMem;
      rc = metadata_getnasn(uri, "MemberIdentities", i_mem, tempURI);

      rc = metadata_getattr(tempURI,
"Name", memberName);
      rc = metadata_getattr(tempURI, "PublicType", memberType);
      returnList = catx("!", returnList, memberName);
      * put i_mem= tempURI= memberName= memberType=;
   
end;

   
return (returnList);
  endsub;
run;

options
 
cmplib=work.myfunctions
;

%let memberList = %sysfunc( md_getMembers(OMSOBJ:IdentityGroup\A5GOWNJA.A50000S0) );
%put NOTE: &=memberList;
Occasional Contributor
Posts: 19

Re: Using data step functions to query identities in metadata

Posted in reply to Bruno_SAS

Thanks Bruno. I've never used PROC FCMP before. I'll have to have a read up on it.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 324 views
  • 4 likes
  • 3 in conversation