BookmarkSubscribeRSS Feed
filippo_kow
Obsidian | Level 7

 Hi all,

 

I have a question regarding retrieving objects from metadata using 4GL code. I have quite simple code to get some metadata information, something like below:

 

data groupmempersons_inf;
            length uri name dispname group groupuri $256 id MDUpdate $20;
            n=1;
            call missing (uri, name, dispname, group, groupuri, id, MDUpdate);
            nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri);
            /*nobj2=metadata_getnobj("omsobj:Machine?@Id contains '.'",n,uri);*/
            if nobj=0 then put 'No persons available.';
            else do 
                while (nobj > 0);
                    rc=metadata_getattr(uri, "Name", Name);
                    rc=metadata_getattr(uri, "DisplayName", DispName);
                    a=1;
                    grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri);
                    if grpassn in (-3,-4) then do;
                        group="No groups";
                        output;
                    end;
                       else do 
                        while (grpassn > 0);
                            rc2=metadata_getattr(groupuri, "Name", group);
                            rc=metadata_getattr(groupuri, "MetadataUpdated", MDUpdate);
                            a+1;
                            output;
                            grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri);
                        end;
                n+1;
                nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri);
            end;
    run;

I am running this code on a couple of servers (on Windows machines - SAS version is 9.4M7, OS is WX64_SV). For some servers it works fine (it returns necessary info), but for one server it returns null dataset (while it should return some records). I think there is something in the configuration that need to be changed. I know that this is very high-level description, but maybe anyone have some idea why it doesn't return any values on one particular server?

 

 Thanks in advance!
 Filip

10 REPLIES 10
Quentin
Super User

When you get  a null dataset, do you get a note in your log "No persons available"?  If so, then the issue is this line:

nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri);

If not, I wonder if your code is covering all possible values for grpassn. It looks like it's assuming the values will always be -3, -4, or greater than 0.  After you calculate grpassn, you could add an assertion to check that assumption:

 

if NOT ( (grpassn IN (-3,-4)) or (grpassn>0) ) then put "ERROR: unhandled value " grpassn= ;

 

 

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
filippo_kow
Obsidian | Level 7

 Hi,

 

Thanks for the info.

 

I will check it, but one more thing - the code was working some time ago on this machine. I think admins changed something in the configuration and after that it doesn't work properly. So I am assuming it is related to some configuration, but of course I will check your suggestion.

filippo_kow
Obsidian | Level 7

 Hi @Quentin ,

 

I did what you asked for and here are the results:

1. There is no "No persons available" note in the log file

2. I added this grpassn handling but there are no errors, so it looks that values -3,-4 and grater than 0 are correct.

 

So my understanding is that the code finds metadata objects, but for some reasons it is not fetching it.

 

In the log file I have only note that there are no observations.

NOTE: The data set WORK.GROUPMEMPERSONS_INF has 0 observations and 13 variables.

 I know it is very hard to investigate, but maybe you have any other hints? Do you think it might be related to server configuration/encoding?

 

 Thanks,

 Filip

filippo_kow
Obsidian | Level 7

 Hi @Quentin ,

 

I just noticed one more thing.

 

I am connecting to metadata using the following options:

options metaserver="<server>"
metaport=8561
metauser="<user>"
metapass="<password>"
metarepository="Foundation";

 

Previously I was using user with full privileges, but when I changed the user to different, I can see some records - but unfortunately not all that are in metadata. Do you think it might be connected to some privileges or so?

 

Also, as I mentioned at the beginning I am running the same code with the same options of different servers and I have problem only with one of them.

Quentin
Super User

Hi, it's definitely possible the problem relates to permissions of the user that runs the code, because that user would need the permissions to read the metadata.

 

I would focus on debugging the DATA step first.  Since you're getting a 0 obs dataset, that suggests that the code never enters the WHILE loop.  

 

I suggest after this line:

if nobj=0 then put 'No persons available.';

add a line:

else if nobj < 0 then put "ERROR: metadata_getnobj returned an unhandled value " nobj= ;

With the code as written, it looks like if metadata_getnobj returns a negative number (or a null), then you would get 0 obs in the output dataset.

 

Basically, I would focus on understanding the DATA step first.  Then once you know which metadata call isn't working like you want, you can dive into the world of metadata permissions to try and figure out why it's not working.  At that point, you might want to call your admin.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
filippo_kow
Obsidian | Level 7

Thanks a lot @Quentin for your reply,

 

You are right - when I added this line and try to run the code from 'admin' account I have an error:

ERROR: metadata_getnobj returned an unhandled value nobj=-4

And when I use my own user I have some records returned (unfortunately not all of them).

 

Well, I am just wondering why my personal user can read only some metadata (only few persons) and not all of them... Maybe you have some idea?

Quentin
Super User

Sorry, I understand the DATA step better than I understand metadata permissions. : ) At least now you know the cause of the problem is the first call to METADATA_GETNOBJ().

 

I know there are lots of rules for metadata permissions.  I suppose it's possible that users could be defined in different metadata folders (or some other metadata 'context') and your account might not have metadata permission to see them all.  You could try opening up SAS Management Console to see if you can see the users there, and if what you see in SMC matches with what you get from this step.

 

Or you might want to ask your admin to explain how metadata permissions might be effecting which users you can see.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
filippo_kow
Obsidian | Level 7

 Hi again @Quentin ,

 

Of course, I fully understand 🙂

 

I really appreciate your help, it was really nice to investigate the problem with MATADATA_GETNOBJ().

 

Thanks again & have a nice rest of the day! 🙂

Quentin
Super User

You have a nice day too! There are plenty of metadata knowledgeable folks in this community.  So hopefully someone else will jump in  with more answers.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
gwootton
SAS Super FREQ
A -4 from metadata_getnobj means that the "n" value is outside of the range, so for example if there are 2 users and you ask for user #3. So in this case it sounds like you're asking for user #1 and it's saying there are 0 users.

This probably means your admin user is no longer defined in Metadata, so is being treated as PUBLIC, and does not have permission to see any user.

As far as why your user ID only has permission to see certain users...are you sure that the other users haven't just been removed (perhaps like your admin user)? If you log in to SAS Management Console as your admin user do you see all the users there?
--
Greg Wootton | Principal Systems Technical Support Engineer

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

Get Started with SAS Information Catalog in SAS Viya

SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 1617 views
  • 3 likes
  • 3 in conversation