Get an alert when a SAS batch job ends with errors
A SAS program runs in batch every night from Task Scheduler or cron. When it ends with errors, or quietly with warnings, the evidence is in a .log file that nobody opens until a table is wrong. SAS does report the problem; checking SYSCC at the end of the program turns that report into an alert.
What SAS reports, and why it still goes unnoticed
Unlike some statistics tools, SAS does give the operating system a meaningful return code. The SAS 9.4 companions for Windows and UNIX list them: 0 when all steps ended normally, 1 when there were warnings, 2 when there were errors, and higher values for ABORT and internal errors. Inside the program, the automatic macro variable SYSCC holds the current condition code: 0 for success and 4 after a warning; after an error it is higher (in practice often 1012).
So why do SAS jobs still fail silently?
- Nobody looks at the code. Task Scheduler shows
0x2in a column, cron discards it. A return code of 1 for warnings is often ignored on purpose, and then real problems such as variable is uninitialized or truncated are ignored with it. - SYSCC can be misleading. It is read/write, so code can reset it. With the default
ERRORCHECK=NORMAL, a failingLIBNAMEorFILENAMEstatement doesn't raise it. And SAS Problem Note 57254 describes a case in SAS 9.4 (reported in M1, fixed in M4) whereSYSCCwas 4 after an error caused by an unmatched quotation mark inSASAUTOS=. SAS's documentation also notes that howSYSCCbecomes the operating-system return code depends on the host. - The run never happened: the server was down, the license expired, the scheduler entry was wrong. No log is written at all.
- The program ran cleanly and produced an empty table, because the source extract was empty. Return code 0.
Report from the end of the program
The code below uses PROC HTTP, part of Base SAS 9.4. It pings TaskBeacon at the start; at the end it checks SYSCC: above 4 it sends /fail with the code, otherwise it counts the rows of your result table and sends them.
/* --- TaskBeacon: top of the program --- */
%let tb = https://taskbeacon.io/ping/your-job-id;
filename tb_out temp;
%macro tb_ping(path);
proc http url="&tb.&path" method="GET" out=tb_out timeout=10; run;
%mend;
%tb_ping(%str(/start));
/* --- your code here --- */
data work.result; set sashelp.class; run;
/* --- TaskBeacon: end of the program --- */
%macro tb_end;
/* SYSCC: 0 = fine, 4 = only warnings, above 4 = errors */
%if &syscc > 4 %then %do;
/* after an error, batch SAS checks only the syntax (OBS=0) and skips steps: leave that mode so the ping runs */
options nosyntaxcheck obs=max replace;
%tb_ping(%str(/fail?rc=&syscc));
%end;
%else %do;
proc sql noprint; select count(*) into :tb_rows trimmed from work.result; quit;
%tb_ping(%str(?rows=&tb_rows));
%end;
%mend;
%tb_end;Not yet tested on a real installation — tell us how it went. The code follows the vendor's documentation. Write to support@taskbeacon.io.
In the app, the Code tab of your job gives you this code with the job's own address instead of your-job-id, and you can untick the parts you don't need.
Replace work.result with the table you care about. Because warnings (4) count as success here, add your own check for the warnings that matter to you, or send another number and set a rule for it; see your own number.
If the server can't reach the internet directly, PROC HTTP accepts a proxy (PROXYHOST=); the SAS page in the Docs covers running SAS in batch with -sysin and the common problems.
What you get
- Failed with the
SYSCCvalue, right after the program ends with errors. - Missed when the program didn't report by its planned time plus grace, including when SAS didn't start.
- Late when it started and runs much longer than usual, for example a step waiting on a locked table.
- Odd data when the row count drops more than 40% below the recent runs or is 0. See 0 rows or far fewer than usual.
Without TaskBeacon
SAS can send email itself: SAS Usage Note 32187 shows a FILENAME EMAIL step that runs when SYSCC signals an error. That needs an SMTP server configured for SAS (EMAILSYS, EMAILHOST), and like any check inside the program it can't report a run that never started. Combine it with a check of the log's date by another job if missed runs matter to you.
Connected Claude or ChatGPT to TaskBeacon? Ask it "what failed last night, and why?" and it answers from your jobs. How that works.
Related
In the Docs: SAS · Number of rows · Statuses.
- Get an alert when an SPSS Statistics production job failsProduction jobs can continue after errors; the log is the only witness.
- Get an alert when a job loads 0 rows, or far fewer than usualExit code 0 says nothing about how many rows arrived.
- Find out when a scheduled job didn't run at allA run that never happened leaves no error to alert on.
TaskBeacon is free to start, with every feature open for now and no credit card. Create a job, paste the code, and the first ping shows up on the job page.
Start free View live demoSources
- SAS Macro Language Reference: SYSCC automatic macro variable (SAS 9.x, undated; checked 2026-11-09)
- SAS 9.4 Companion for Windows: return codes (0 normal, 1 warnings, 2 errors …) (SAS 9.4, undated; checked 2026-11-09)
- SAS Problem Note 57254: SYSCC is 4 after an error from an unmatched quotation mark in SASAUTOS= (fixed in 9.4M4) (2015-12-14, updated 2016-02-02, old: a specific bug, fixed in 9.4M4)
- SAS Usage Note 32187: How can I send an email if an error occurs in my log? (undated)
- Base SAS 9.4 Procedures Guide: PROC HTTP (SAS 9.4, undated)
Page checked against its sources on 2026-11-09. Menus and limits of other products change; if something here no longer matches, write to support@taskbeacon.io.