BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nigel_Pain
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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;

Nigel_Pain
Lapis Lazuli | Level 10

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

BrunoMueller
SAS Super FREQ

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;
Nigel_Pain
Lapis Lazuli | Level 10

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 1259 views
  • 4 likes
  • 3 in conversation