3

i have some stored processes with identical names. To identify which process is running at the moment, i need to know the id of the stored process in the metadata. Can i retrieve the STP-id somewhere? I could not find a variable which holds the id. I only found symget('sysjobid'); which returns the unix-processid, not the id of the stored process.

Typical a stored process id looks like this: A5DF0R0G.B80001L7

I need to know the id from within the process which is running, to retrieve some properties of the process from the metadata.
Any other solution to identify the process exactly in the metadata would also be welcome, but i can not use his name, because it can occur several times for differents processes.

for example something like:

put 'name:' &_program; /*this already works and returns the name of the stored process*/
put 'id:' ?; /*need to know the id of the process, because name is not distinct*/
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
kl78
  • 1,628
  • 1
  • 16
  • 26
  • Do you mean the Session ID? (`&_SESSIONID`)? – Joe Jul 15 '15 at 15:40
  • No, i saw the sessionID in the log, but this is not the id of the stored process. When a Stored process is written in the metadata, he gets an unique-id, that is what i am looking for. it looks like this: Id, A5DF0R0G.B80001L7, so always 8 chars dot 8 chars, i am not sure if it is possible to retrieve it from within the process at all, but maybe someone knows it – kl78 Jul 15 '15 at 15:42
  • Ahh, the 17-character metadata object ID. Unfortunately I don't know how to obtain that, perhaps someone will. – Joe Jul 15 '15 at 15:48
  • Yes, sorry if you could not get this from my question, but english is not my native language, so i have some difficulties to explain it right^^ – kl78 Jul 15 '15 at 15:49
  • No, question is fine, I just don't know enough about metadata server to understand it fully. From googling around, this is likely either entirely trivial or nearly impossible - as I don't see any papers describing how to do it... if it were me I'd probably look at the metadata server entries and see if it's possible to find a third link (maybe the _sessionID is stored for the last time ran, for example) in there. – Joe Jul 15 '15 at 15:49

2 Answers2

4

It is actually pretty easy now that I look at it.

I created this sample STP (named "Doms Hello World") in the "My Folder" folder.

data _temp;
X = "HELLO WORLD";
path = "&_PROGRAM";
format type ID $200.;
rc= metadata_pathobj("",path,"StoredProcess",type,ID);
run;

proc print data=_temp noobs;
run;

You can use the metadata_pathobj() function to get the ID and TYPE of an element by the path.

This returns

X            path                                               type            ID                  rc
HELLO WORLD /User Folders/dpazzula/My Folder/Doms Hello World   ClassifierMap   A5XQ9K3Z.BA0002BQ   1

In both EG and via the Web App.

DomPazz
  • 12,415
  • 17
  • 23
  • ah, ok, did not know the pathobj function yet, always retrieved data by name or id, i will try this tommorrow, ty so far. But i have more then one process in the folder, so i have to do path search first and then search by name afterwards? – kl78 Jul 15 '15 at 17:20
  • No, the name is the last item in the path. So the name is "Doms Hello World" and the folder in "My Folder". – DomPazz Jul 15 '15 at 17:28
  • ah, ok, pathobj also includes the processname in the search, so that is even nicer, ty – kl78 Jul 15 '15 at 17:42
0

I don't think a stored process has an ID, but it is unique in terms of its location and name.

User _PROGRAM macro variable to determine what stored procedure is running. It will have a format of "/SAS Folder/Stored Procedure Folder/Stored Procedure Name".

Something like A5DF0R0G.B80001L7 ID of the stored procedure useful when running IOM applications, but I don't think it would be that useful when it comes determining what stored procedure created something and where it was saved at the time, so I would go with "_PROGRAM".

In case you after the ID anyways, use this code (credit: https://support.selerity.com.au/entries/23169736-Example-Data-Step-View-of-Stored-Procedures-in-Metadata):

 ******************************************************************************
* Purpose: Create a dynamic view of Stored Procedures registered in Metadata
* Notes  : You must establish a Metadata connection prior to running
******************************************************************************;
data work.stplist(drop=_: label="SAS Stored Process List") /     view=work.stplist;
 length id $17 _uri name description _modified _created location _location    $256;
  length created modified 8;
  format created modified datetime.;
  label id="Metadata ID"
        name="Stored Process Name"
        description="Description"
        location="Folder Location"
        created="Created"
        modified="Last Modified";
  _nobj=1;
  _n=1;
  call missing(id, _uri, name, description, _modified, _created, _location);
  do while(_n le _nobj);
    _nobj=metadata_getnobj("omsobj:ClassifierMap?@PublicType='StoredProcess'",_n,_uri);
    _rc=metadata_getattr(_uri,"Id",id);
    _rc=metadata_getattr(_uri,"Name",name);
    _rc=metadata_getattr(_uri,"Desc",description);
    _rc=metadata_getattr(_uri,"MetadataCreated",_created);
    _rc=metadata_getattr(_uri,"MetadataUpdated",_modified);
    created=input(_created,anydtdtm.);
    modified=input(_modified,anydtdtm.);
    * Get folder object the current STP is in *;
    _rc=metadata_getnasn(_uri,"Trees",1,_uri);
    * Get folder name the current STP is in *;
    _rc=metadata_getattr(_uri,"Name",location);
    _tree=1;
    * Loop up the folder hierarchy *;
    do while (_tree>0);
      * Get the parent folder object *;
      _tree=metadata_getnasn(_uri,"ParentTree",1,_uri);
      if _tree > 0 then do;
        * If there was a parent folder, get the name *;
        _rc=metadata_getattr(_uri,"Name",_location);
        * Construct the path *;
        location=catx('/',_location,location);
      end;
    end; * Folder Hierachy *;
    location = '/'||location;
    output;
    _n=_n+1;
  end;
run;

Regards, Vasilij

Vasilij Nevlev
  • 1,449
  • 9
  • 22
  • I konw how to get id if i have a stp with a unique name. My process works quite similar to your post, but i dont want to get all stored processes and build the path, because that is not very performant, in the case i just want one specific process and need to identify it by something other then the name, because names are not uniqe, and i get more then one result if searching by name. – kl78 Jul 15 '15 at 17:40
  • My first idea was getting it by his id, because the id is unique.I did not know the function to search processes by path which DomPazz posted. But if this works like i think, i can identify the process by the combination of name and path, because i have about thousand processes and dont want to loop through all. But ty for your answer – kl78 Jul 15 '15 at 17:40