2

In SAS DIS, I want to reference the job name in code. I know that the global variable etls_jobName contains this information, but when I assign this value to a field and view the output, I get '.'.

Ultimately, I'd also like to be able to get the path name (in the folder structure of the job) and I'm not sure where that sort of information lives.

Much Gratitude.

Joe
  • 62,789
  • 6
  • 49
  • 67
Rookatu
  • 1,487
  • 3
  • 21
  • 50
  • 4
    I know zero about DIS, but is etls_jobName a macro variable instead of a data variable perhaps? `"&etls_jobname."` perhaps? – Joe Apr 22 '15 at 14:21
  • 1
    I echo what @Joe says, make sure you put quotes around the macro variable. Also, the fact that you are getting a . in the field tells me you might be trying to assign a character value to a numeric field. Make sure the field is character and long enough to hold the value of &etls_jobName. – DomPazz Apr 22 '15 at 14:32
  • Thanks! This worked great for the job name. Any ideas about the folder hierarchy? – Rookatu Apr 22 '15 at 17:58
  • Try %put _global_ ; and look at the log. Typically the SAS BI clients make a lot of global macro vars with info like that. – Quentin Apr 22 '15 at 22:33
  • Sorry , should be underscores around global. Not italics. %put _ global _ ; with no spaces. Darn phone... – Quentin Apr 22 '15 at 22:34
  • Well, sorry to say I checked the global symbol table in DIS 4.5, and I don't see anything with the metadata path to the job. Surprising. It's there in EG (path to the .egp file), and it's there when you run stored processes through IDP/SPWA. Ugh. – Quentin Apr 22 '15 at 23:51

1 Answers1

2

For the job flow metadata path, you can try using the below code. The code picks up job name from the &etls_jobName macro variable and extracts metadata folder path of the job. To know more about the functions that are being used, please refer to the SAS Language Interfaces to Metadata. Hope this helps!

data path_output;
    length jobName $ 100 uri headuri $ 256 jobPath head_path $ 500 ;

    jobName="&etls_jobName";
    rcJob =metadata_getnobj("omsobj:Job?@Name ='&etls_jobName'",1,uri);
    rcHead=metadata_getnasn(uri,"Trees",1,headuri);
    rcPath=metadata_getattr(headuri,"Name",jobPath);

    rcHead = 1;
    do while(rcHead>0);
        rcHead=metadata_getnasn(headuri,"ParentTree",1,headuri);
        rcPath=metadata_getattr(headuri,"Name",head_path);

        if (rcHead>0) then jobPath = catx('/',head_path,jobPath);
    end;

    output;
    keep jobName jobPath;
run;

proc print;
run;

UPDATE:

If Job Flow URI needs to be picked based on Job Flow name then use what is show in the code above i.e.:

rcJob =metadata_getnobj("omsobj:Job?@Name ='&etls_jobName'",1,uri);

If Job Flow URI needs to be picked based on Metadata id then use :

rcJob =metadata_getnobj("omsobj:Job?@Id ='&jobID'",1,uri);  
sushil
  • 1,576
  • 10
  • 14
  • This worked great sushil! Thanks again so much. The only thing I had to do was concatenate the jobPath with a `'/'` before the loop, but this was exactly what I needed. +1 – Rookatu Apr 28 '15 at 20:14
  • oh just realized there was a typo in the code and that's why you had to add the '/' .. I had written cats instead of catx .. i have updated the code. – sushil Apr 28 '15 at 23:08
  • Hey Sushil. I just encountered some unexpected behaviour with this code: if two different folders have a job with the same name then the path generated by this code may be the path of the wrong job. I guess it is looking for a leaf name in the folder structure which matches the name of the job then building up from there, but there are multiple leaves with the same name. Any idea how to fix this without imposing a naming convention on jobs? Thanks! – Rookatu Apr 30 '15 at 18:43
  • there is a way to resolve this issue. we could code to start looking for job using metadata id instead of job name. Metadata id is unique id assigned within a repository. Going metadata id way can make sure that the correct jobflow path is picked. The metadata id of the jobflow shows up on the Basic Properties panel( if it's not showing check View->Basic Properties . It should start showing on bottom left screen). Now for the code part, if metadata id is like "AXXXXXXX.BXXXX256" then use : rcJob =metadata_getnobj("omsobj:Job?@Id ='AXXXXXXX.BXXXX256'",1,uri); – sushil Apr 30 '15 at 19:03
  • Thanks again for such a quick and helpful reply sushil! My issue here is that this would require a user to hard code the job id in. Using your suggestion, I found it is better to use `rcJob =metadata_getnobj("omsobj:Job?@Id ='&jobID'",1,uri);` instead. Thanks! – Rookatu Apr 30 '15 at 19:21
  • Cool...I had totally forgotten about jobid macro variable. Thanks for letting me know! – sushil Apr 30 '15 at 19:26
  • For some reason, this code stopped working. Now the job path is empty, and I've traced it to the initial line where `uri` is given its value. The log is giving "NOTE: Variable uri is uninitialized", which of course causes headuri and head_path to be uninitialized. When I write `job_id = "&jobID"` and `PUT job_id` I do get the valid job id. Any ideas here? Thanks! – Rookatu May 06 '15 at 14:48
  • can you execute your job flow and check on the log tab the execution in the log where the value of &jobId is resolved => rcJob =metadata_getnobj("omsobj:Job?@Id ='&jobID'",1,uri) Also, after the above code put put rcJob=; to get the value rcJob variable value. This should help me in debugging. – sushil May 06 '15 at 17:12
  • Hey Sushil. As always you are very helpful, and it is much appreciated. In this case, I think there was an error with the metadata server. I reconnected. Currently, the issue is not persisting and cannot be reproduced. I will return with that detail if the issue resurfaces however. Thanks again! – Rookatu May 06 '15 at 17:53