0

I am trying to invoke a sas script using python and subprocess. This is my code:

    proc = Popen(self.cmd, shell=True, stdout=PIPE, stderr=STDOUT)
    proc.wait()
    standard_output, standard_error = proc.communicate()
    if proc.returncode == 0:
        log.info("Successfully executed execute_shell_command")
    elif proc.returncode == 1:
        self.status_message = "return code 1 from" + " ".join(self.cmd) + "error msg: " + str(standard_error)
        self.flag = 1
        raise ValueError(self.status_message)
    elif proc.returncode > 1:
        self.status_message = "Error occurred while executing command on shell :" + " ".join(self.cmd) + ' ' + standard_error
        self.flag = 1
        raise ValueError(self.status_message)

    self.cmd  = [sas_path,'-config',sas_config_path,'-sysin',sas_code_path]

I am not including the autoexec_path for SAS,because I did not find any autoexec file. if I have the autoexec file then,

self.cmd = [sas_path,'-config',sas_config_path,'-autoexec',autoexec_path,'-sysin',sas_code_path]

The problem is the SAS code executes successfully, but proc.returncode is not equal to 0. Therefore, my python code doesn't know that the code ran successfully.
Is there anything that I am doing wrong?

2
  • can you set -log option and check whats wrong? Commented Oct 24, 2019 at 13:06
  • My sas code issued warnings,which is why the return code was 1. Commented Oct 29, 2019 at 5:30

1 Answer 1

1

You might have warnings in the log.

From the docs, "SAS® 9.4 Companion for Windows, Fifth Edition"

Return Codes and Completion Status

The return code for the completion of a SAS job is returned in the Windows batch variable, ERRORLEVEL.

Values for the ERRORLEVEL Variable

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Richard. My SAS code log had warnings, which is why I was getting return code 1. This was very helpful.
Good to hear that and welcome to SO. Be sure to mark answers to your questions and answers to other questions you find helpful. stackoverflow.com/help/someone-answers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.