DATA Step, Macro, Functions and more

How to get return code of a sh job which calls a sas job inside a macro

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

How to get return code of a sh job which calls a sas job inside a macro

Hi

 

I ahve to execute a batch scripts(sh script) which calls a SAS job inside a macro, I have to check the return code of the same . How to do ?

%do i=1 to &max;/*Max holds 9 thats 9 jobs*/

 

%let path = /app/jobs;

x "&path/&&jobs&i...&extn";/*extn is sh*/

 %if rc ge 0 /*I have to do this but unabel to get rc value*/

 

Kindly advise

Thanks,
Sandhya S

 

 


Accepted Solutions
Solution
‎11-29-2017 02:32 AM
Super User
Posts: 10,534

Re: How to get return code of a sh job which calls a sas job inside a macro

Since included code is always executed in the context of your local SAS, check &syscc for the current return code status.

 

You should also read through the documentation of the other automatic macro variables.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Super User
Posts: 10,534

Re: How to get return code of a sh job which calls a sas job inside a macro

First of all you need to make sure that the shell script returns the RC from SAS. After executing an external command, check the &sysrc automatic macro variable. It contains the return code from the x statement.

For reference, see here: http://documentation.sas.com/?docsetId=mcrolref&docsetTarget=p07ugdul4v0llpn1denhfknmr7sb.htm&docset...

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 40

Re: How to get return code of a sh job which calls a sas job inside a macro

Posted in reply to KurtBremser
Hi @KurtBremser

Thanks for your reply. How to check the return code of a SAS job which was executed using below statement ?

%include /app/jobs/J_ABC.sas";

Thanks and Regards
Sandhya S
Solution
‎11-29-2017 02:32 AM
Super User
Posts: 10,534

Re: How to get return code of a sh job which calls a sas job inside a macro

Since included code is always executed in the context of your local SAS, check &syscc for the current return code status.

 

You should also read through the documentation of the other automatic macro variables.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 5,914

Re: How to get return code of a sh job which calls a sas job inside a macro

%include execute the code in the calling session, hence no session rc.
Data never sleeps
Contributor
Posts: 40

Re: How to get return code of a sh job which calls a sas job inside a macro

Hi @LinusH

I understand that . But if there anyway i can know whether the job is successful or not?
Super User
Posts: 5,914

Re: How to get return code of a sh job which calls a sas job inside a macro

Not sure what you mean by "Job" in this context.

For the "calling" session there will be a rc of course, but the included code is not a job.

If you want to monitor individual steps you can check rc for these. 

If I try to read between the lines, I think you want to monitor each program separately, and the %include's are not a good choice.

Better to set job flows up in a decent scheduler, and have that as a central point of control.

Data never sleeps
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 391 views
  • 0 likes
  • 3 in conversation