1

I am working in a configuration that uses the IOM to connect to the metadata server - hence there are no automatic macro variables in my environment to determine the user id (we are using a pooled workspace server with a generic host account).

Is there a short piece of code which can be used to query the metadata server for the SAS user id?

Allan Bowe
  • 12,306
  • 19
  • 75
  • 124

1 Answers1

1

The following is quite long winded, and could probably be shortened - but it does the job!

data _null_;
call symput('login_id',''); /* initialise to missing */
n = 1;
length loginUri person $ 512;
nobj = metadata_getnobj("omsobj:Login?*",n, loginUri);
if (nobj>0) then do;
    length __uri __objName __porig personUri $256;
    __porig = loginUri;
    __uri = '';
    __objName = '';
    __n = 1;
    __objectFound = 0;
    personUri = "";
    __numObjs = metadata_getnasn(__porig ,"AssociatedIdentity", 1, __uri);
    do until(__n > __numObjs | __objectFound );
        __rc = metadata_getattr(__uri, "PublicType", __objName);
        if __objName="User" then do;
            __rc=metadata_getattr(__uri, "Name", __objName);
            __objectFound = 1;
            personUri = __uri;
        end;
        else do;
            __n = __n+1;
            rc = metadata_getnasn(__porig, "AssociatedIdentity", __n, __uri);
        end;
    end;
    if upcase("N")="Y" and not __objectFound then do;
        put "*ERROR*: Object with  PublicType=" "User" " not found for parent " loginUri " under AssociatedIdentity association";
        stop;
    end;
    ;
    rc = metadata_getattr(personUri, "Name", person);
    call symput("login_id", trim(person));
end;
run;
%put &login_id;
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
  • 1
    A minor tweak might be to add a `call symput` at the top of your data step to set the macro variable "login_id" to blank. And unless you really need that data set `S` for some reason, I'd use `data _null_`. Looks good in any case. – BellevueBob Nov 19 '12 at 16:26