Carl
Carl

Reputation: 5779

Dealing with warnings when running SAS in batch

I like to use Makefiles so I frequently run SAS programs in batch from the command line. SAS will return a non-zero status of 1 if it encounters any warnings, and a non-zero status of 2 or greater if there is an error.

This means the make errors out even if there are only warnings. I can force the Makefile to ignore non-zero statuses, but then it also ignores actual errors.

How would I write a Makefile such that it errors out if I get a non-zero status of 2 or greater, but continues for a non-zero status of 1?

ex:

myOutput.sas7bdat: myProgram.sas
   "path/to/sas.exe" $<
## ignore errors
myOutput.sas7bdat: myProgram.sas
   -"path/to/sas.exe" $<

Upvotes: 2

Views: 252

Answers (1)

user657267
user657267

Reputation: 21000

You can either use .ONESHELL if your version of make supports it (4.0+ for windows)

.ONESHELL:
myOutput.sas7bdat: myProgram.sas
    "path/to/sas.exe" $<
    if %ERRORLEVEL% gtr 1 exit /b 1

Or you can wrap those two lines into a batch file (replacing $< with %1 in the file)

myOutput.sas7bdat: myProgram.sas
    whatever.cmd $<

Upvotes: 1

Related Questions