Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error handling using macro variables

Status
Not open for further replies.

FatCaptain

Programmer
Jun 9, 2010
4
GB
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.

Code:
rsubmit;

data dataset_backup ;
set  dataset ;
run ;

data dataset2_backup ;
set  dataset2 ;
run ;

endrsubmit;

I've been playing around with &syserr and &_efierr_ to obtain an error flag and %sysrput to get the variable on the server to the local machine.

Once I have this error flag on the local machine, I would like to use it to alter the contents of an automated email as shown in this thread;


e.g.
Code:
*If the code has no errors;
%if &localerrorvar = 0 %then %do;
put '.Subject = "Files backed up successfully"';
%end;
*If the code has fallen over or has errors;
%if &localerrorvar = 1 %then %do;
put '.Subject = "FILE BACKUP ERROR"';
%end;

Any help with this would be appreciated!

Cheers,

FatCaptain.
 
Can't you have the server send the email? If it can then your error macro var can be used.

Another way you can do this task is to write the error (or lack of error) to a text file and then have the local sas read that text file in. Of course you would have to use a timestamp type of file name so that mult. runs of the same code don't overwrite each other.

Have you tried the %sysrput macro statement. This statement will allow a value generated in the Remote session(server) to be available in the client session. You could set the error code to that macro var and have the client 'see' that value.

Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top