Use SYSRPUT to determine whether a SAS/Connect session failed

From sasCommunity
Jump to: navigation, search

Use the SYSRPUT statement to copy the system condition code from a remote SAS/Connect session back to your local SAS session. This lets your local session know what happened in the remote session.

If you remote submit SAS statements, your local session will not detect the failure of those statements.

Consider this code, which attempts to run a non-existent procedure in a remote session:

options errorabend;                         
                                                                                        
rsubmit;                                    
                                            
   proc not-a-valid-proc-name;              
   run;                                     
                                            
endrsubmit;                                 
                                            
%put NOTE: The current SYSCC is &SYSCC.;    
                                            
proc print data=sashelp.class;              
run;                                        

The log shows that an error has occurred, but execution continues as if nothing went awry:

20         rsubmit;                                                   
NOTE: Remote submit to REMORA commencing.                             
4       proc not-a-valid-proc-name;                                   
ERROR: Procedure NOT not found.                                       
5       run;                                                          
                                                                      
NOTE: The SAS System stopped processing this step because of errors.  
                                                                                                    
NOTE: Remote submit to REMORA complete.                               
22         %put NOTE: The current SYSCC is &SYSCC.;                   
NOTE: The current SYSCC is 0                                          
24         proc print data=sashelp.class;                             
25         run;                                                       
                                                                      
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The PROCEDURE PRINT printed page 1.                             
                                                                                                                                           
ERROR: Errors printed on page 2.                                      
                                                                      
NOTE: The SAS session used 0.15 CPU seconds.                          

If you want errors in a remote session to cause your local session to stop executing, use the SYSRPUT statement to pass the remote condition code back to the local session:

options errorabend;                             
                                                
%let mysyscc = 36;                              
                                                
rsubmit;                                        
                                                
   proc not-a-valid-proc-name;                  
   run;                                         
                                                
   %put NOTE: Remote SYSCC=&SYSCC.;             
                                                
   %sysrput mysyscc=&SYSCC.;                    
                                                
endrsubmit;                                     
                                                
%let syscc = %sysfunc(max(&SYSCC., &MYSYSCC.)); 
                                                
%put NOTE: The current SYSCC is &SYSCC.;        
                                                
proc print data=sashelp.class;                  
run;                                            

The system condition code is set, so the proc print in the local session is not executed:

20         %let mysyscc = 36;                                         
22         rsubmit;                                                   
NOTE: Remote submit to REMORA commencing.                             
4       proc not-a-valid-proc-name;                                   
ERROR: Procedure NOT not found.                                       
5       run;                                                          
                                                                      
NOTE: The SAS System stopped processing this step because of errors.  
NOTE: PROCEDURE NOT used:                                             
      real time           0.00 seconds                                
      cpu time            0.00 seconds                                
                                                                      
6                                                                     
7       %put NOTE: Remote SYSCC=&SYSCC.;                              
NOTE: Remote SYSCC=3000                                               
8                                                                     
9       %sysrput mysyscc=&SYSCC.;                                     
NOTE: Remote submit to REMORA complete.                               
24         %let syscc = %sysfunc(max(&SYSCC., &MYSYSCC.));            
26         %put NOTE: The current SYSCC is &SYSCC.;                   
NOTE: The current SYSCC is 3000                                       
28         proc print data=sashelp.class;                             
29         run;                                                       
                                                                      
NOTE: SAS set option OBS=0 and will continue to check statements.     
      This may cause NOTE: No observations in data set.               
                                                                                                                                            
ERROR: SAS ended due to errors.                                       
       You specified: OPTIONS ERRORABEND;.                            
ERROR: Errors printed on page 2.                                      

Two things to note:

  1. Set the value of the condition code macro variable in the local session to a non-zero value at the start; if something goes so badly in the remote session that the SYSRPUT statement is never executed, you'll have a value of MYSYSCC that indicates failure. If the remote session succeeds, the non-zero value will be overriden by the SYSRPUT.
  2. Use the MAX function , wrapped in %SYSFUNC, to set the condition code to the greater of the local condition code and the remote return code. If your local session had already set a non-zero condition code for some reason, you don't want to lose that information.

Submitted by Jack Hamilton. Contact me at my Discussion Page.