Chapter Contents

Previous

Next
SAS/CONNECT User's Guide

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 when the procedure terminates due to errors.

You can also use the %SYSRPUT macro statement on the remote host to send the value of the SYSINFO macro variable back to the local SAS session. Thus, you can submit a job to the remote host and test whether a PROC UPLOAD or a PROC DOWNLOAD step has successfully completed before beginning another step on either the remote host or the local host.


Program

Suppose that you have a transaction file on your local host and you want to upload it to the remote host, and then use it to update a master file. You can test the results of the PROC UPLOAD step on the remote host by checking the value of the SYSINFO macro variable.

The SYSINFO macro variable can be used to determine if 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 remote host back to the local session. Your SAS session on the local host 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 'local-SAS-data-library';
   libname backup 'local-SAS-data-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 'remote-SAS-data-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;
[1] Associate a libref with the SAS data library that contains the transaction data set on the local host.
[2] Send the PROC UPLOAD statement and the UPDATE_EMPLOYEE macro to the remote host 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) on the remote host.
[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 on the local host and puts the value that is stored in the SYSINFO macro variable into UPLOAD_RC. The UPLOAD_RC macro variable is passed to the local host and can be tested to determine if the PROC UPLOAD step was successful.
[5] Tests the SYSINFO macro variable on the remote host. 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 remote host sends messages to the SAS log (which appear in the local SAS session) notifying you that the step has failed.
[7] Executes the UPDATE_EMPLOYEE macro on the remote host.
[8] The CHECK_UPLOAD macro is executed on the local host because it follows the ENDRSUBMIT statement.
[9] Tests the value of the UPLOAD_RC macro variable created by the %SYSRPUT macro statement on the remote host to see if 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 on the local host by using the COPY statement in the DATASETS procedure.
[11] Executes the CHECK_UPLOAD macro on the local host.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.