DATA Step, Macro, Functions and more

Error handling - Is there a variable set if any error occurs?

Reply
Contributor
Posts: 29

Error handling - Is there a variable set if any error occurs?

Hi,

I'm trying to generate a variable in SAS which shows whether the code has run without any errors.

The main body of the code is run on the server using an rsubmit command. The error variable needs to be available locally on my pc.

The code is very simple as it just backs up some SAS datasets e.g.



rsubmit;

data dataset_backup ;
set dataset ;
run ;

data dataset2_backup ;
set dataset2 ;
run ;

endrsubmit;



Do I need to include a error check in each and every data step or is there a single variable which gets set if any error anywhere is found?

I've tried playing around with &syserr and &_efierr_ to obtain an error flag and %sysrput to return it to the local pc from the server but can't get anything to work.

Any help with this would be appreciated.

Thanks,

Fat Captain.
Super User
Posts: 10,035

Re: Error handling - Is there a variable set if any error occurs?

Posted in reply to FatCaptain
As far as i remember , there are two auto macro variables ( &syserrortext &syswarningtxt )
which include the last error text and the last warning txt.




Ksharp
Valued Guide
Posts: 2,177

Re: Error handling - Is there a variable set if any error occurs?

Posted in reply to FatCaptain
have you tried &SYSCC
Respected Advisor
Posts: 3,799

Re: Error handling - Is there a variable set if any error occurs?

Using Mr. C's suggestion to use CC you might do something like this.

[pre]
286 proc transpose data=sashelp.class;
287 var sex;
288 run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.DATA14 has 1 observations and 20 variables.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
real time 0.48 seconds
cpu time 0.00 seconds


289 %sysfunc(ifC(&syscc,%nrstr(%put NOTE: BAD CC ENDSAS?Smiley Wink,%nrstr(%put NOTE: All good keep going)));
NOTE: All good keep going
290
291 proc transpose data=sashelp.class;
292 var sexx;
ERROR: Variable SEXX not found.
293 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.DATA15 may be incomplete. When this step was stopped there were 0 observations and 0 variables.
NOTE: PROCEDURE TRANSPOSE used (Total process time):
real time 0.54 seconds
cpu time 0.00 seconds

294 %sysfunc(ifC(&syscc,%nrstr(%put NOTE: BAD CC ENDSAS?Smiley Wink,%nrstr(%put NOTE: All good keep going)));
NOTE: BAD CC ENDSAS?

[/pre]



For batch jobs a simple ENDSAS statement should be good. For a DMS session you want to keep alive you will need something else, but I'm not sure what.

A little searching at support.sas.com I find DM command WATTENTION. http://support.sas.com/kb/38/749.html

[pre]
%sysfunc(ifC(&syscc,%nrstr(dm 'WATTENTION'Smiley Wink,%nrstr(%put NOTE: All good keep going)));
[/pre]

WATTENTION


Message was edited by: data _null_;

Well WATTENTION does bring up the dialogue but when you select Cancel Submitted Statements it does not cancel them.

http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0709C&L=sas-l&P=R17140 Message was edited by: data _null_;
Ask a Question
Discussion stats
  • 3 replies
  • 177 views
  • 0 likes
  • 4 in conversation