Example 3. Compute Services and Data Transfer Services Combined: Macro Capabilities

Purpose

SAS/CONNECT is fully functional from within the macro facility. Both the UPLOAD and the DOWNLOAD procedures can update the macro variable SYSINFO and set it to a nonzero value if the procedure terminates because of errors.
You can also use the %SYSRPUT macro statement in the server session to send the value of the SYSINFO macro variable back to the client session. Thus, you can submit a job to the server and test whether a PROC UPLOAD or a PROC DOWNLOAD step successfully completed before beginning another step in either the client or server session.

Program

This program includes a transaction file that is located on the client, which will be uploaded to a server in order to update a master file. You can test the results of the PROC UPLOAD step in the server session by checking the value of the SYSINFO macro variable.
The SYSINFO macro variable can be used to determine whether the transaction file was successfully uploaded. If successful, the master file is updated with the new information. If the upload was not successful, you receive a message that explains the problem.
You can use the %SYSRPUT macro statement to send the return code from the server session back to the client session. The client session can test the results of the upload and, if it is successful, use the DATASETS procedure to archive the transaction data set.
1 libname trans
'client-SAS-library';
   libname backup
'client-SAS-library';2
 rsubmit;3
    proc upload data=trans.current out=current;
      run;
4
    %sysrput upload_rc=&sysinfo;
      %macro update_employee;
5
       %if &sysinfo=0 %then %do;
            libname perm
'server-SAS-library';
            data perm.employee;
               update perm.employee current;
               by employee_id;
            run;
         %end;
6
       %else %put ERROR: UPLOAD of CURRENT 
                    failed. Master file was
                    not updated.;
      %mend update_employee;7
    %update_employee;
   endrsubmit;
8
 %macro check_upload;9
    %if &upload_rc=0 %then %do;10
       proc datasets lib=trans;
            copy out=backup;
         run;
      %end;
   %mend check_upload;11
 %check_upload;
1Associates a libref with the SAS library that contains the transaction data set and backup data in the client session.
2 Sends the PROC UPLOAD statement and the UPDATE_EMPLOYEE macro to the server session for execution.
3 Because a single-level name for the OUT= argument is specified, the PROC UPLOAD step stores CURRENT in the default library (usually WORK) in the server session.
4 If the PROC UPLOAD step successfully completes, the SYSINFO macro variable is set to 0. The %SYSRPUT macro statement creates the UPLOAD_RC macro variable in the client session, and puts the value that is stored in the SYSINFO macro variable into UPLOAD_RC. The UPLOAD_RC macro variable is passed to the client session and can be tested to determine whether the PROC UPLOAD step was successful.
5 Tests the SYSINFO macro variable in the server session. If the PROC UPLOAD step is successful, the transaction data set is used to update the master data set.
6 If the SYSINFO macro variable is not set to 0, the PROC UPLOAD step has failed, and the server session sends messages to the SAS log (which appear in the client session) notifying you that the step has failed.
7 Executes the UPDATE_EMPLOYEE macro in the server session.
8 The CHECK_UPLOAD macro is defined in the client session because it follows the ENDRSUBMIT statement.
9 Tests the value of the UPLOAD_RC macro variable that was created by the %SYSRPUT macro statement in the server session to determine whether the PROC UPLOAD step was successful.
10 When the transaction data set has been successfully uploaded and added to the master data set, the transaction file can be archived in the client session by using the COPY statement in the DATASETS procedure.
11 Executes the CHECK_UPLOAD macro in the client session.