if (&amount < 0) or (&amount > 1000) then
do;
erroron borrowed;
_msg_='Amount must be between $0 and $1,000.';
stop;
end;
else erroroff borrowed;
%mend ckamount;
/* Display an error message if RATE */
/* is less than 0 or greater than 1.5 */
%macro ckrate(rate);
if (&rate < 0) or (&rate > 1) then
do;
erroron interest;
_msg_='Rate must be between 0 and 1.5';
stop;
end;
else erroroff interest;
%mend ckrate;
/* Open the window with BORROWED at 0 and INTEREST at .5. */
INIT:
control error;
borrowed=0;
interest=.5;
return;
MAIN:
/* Run the macro CKAMOUNT to validate */
/* the value of BORROWED. */
%ckamount(borrowed)
/* Run the macro CKRATE to validate */
/* the value of INTEREST. */
%ckrate(interest)
/* Calculate payment. */
payment=borrowed*interest;
return;
TERM:
return;
SAS/CONNECT Interfaces
Overview of SAS/CONNECT Interfaces
Many times when working with macros and SAS/CONNECT, the results that you see
are not what you expected. When using RSUBMIT within the macro facility, it is
important to have an understanding of what happens at compile time versus what
happens at execution time. Knowing the behavior of this interaction helps you when
using macros and SAS/CONNECT together. For more information, see “Use the Macro
Facility with SAS/CONNECT” in SAS/CONNECT Users Guide.
112 Chapter 8 Interfaces with the Macro Facility
Using %SYSRPUT with SAS/CONNECT
The %SYSRPUT macro statement is submitted with SAS/CONNECT to a remote host
to retrieve the value of a macro variable stored on the remote host. %SYSRPUT assigns
that value to a macro variable on the local host. %SYSRPUT is similar to the %LET
macro statement because it assigns a value to a macro variable. However, %SYSRPUT
assigns a value to a variable on the local host, not on the remote host where the
statement is processed. The %SYSRPUT statement places the macro variable in the
current scope of the local host.
Note: The names of the macro variables on the remote and local hosts must not contain
a leading ampersand.
The %SYSRPUT statement is useful for capturing the value of the automatic macro
variable SYSINFO and passing that value to the local host. SYSINFO contains return-
code information provided by some SAS procedures. Both the UPLOAD and the
DOWNLOAD procedures of SAS/CONNECT can update the macro variable SYSINFO
and set it to a nonzero value when the procedure terminates due to errors. You can use
%SYSRPUT 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 DOWNLOAD step has successfully completed before beginning
another step on either the remote host or the local host.
To use %SYSRPUT, you must have invoked a remote SAS windowing environment
session by submitting the DMR option with the SAS command. For more information
about using %SYSRPUT, see “The %SYSLPUT and %SYSRPUT Statements” in
SAS/CONNECT Users Guide.
To create a new macro variable or to modify the value of an existing macro variable on a
remote host or a server, use the %SYSLPUT macro statement.
Example Using %SYSRPUT to Check the Value of a Return Code on
a Remote Host
This example illustrates how to download a file and return information about the success
of the step. When remote processing is completed, the job checks the value of the return
code stored in RETCODE. Processing continues on the local host if the remote
processing is successful. In this example, the %SYSRPUT statement follows a PROC
DOWNLOAD step, so the value returned by SYSINFO indicates the success of the
PROC DOWNLOAD step:
/* This code executes on the remote host. */
rsubmit;
proc download data=remote.mydata out=local.mydata;
run;
/* RETCODE is on the local host. */
/* SYSINFO is on the remote host. */
%sysrput retcode=&sysinfo;
endrsubmit;
/* This code executes on the local host. */
%macro checkit;
%if &retcode = 0 %then
%do;
further processing on local host
%end;
SAS/CONNECT Interfaces 113
%mend checkit;
%checkit
To determine the success or failure of a step executed on a remote host, use the
%SYSRPUT macro statement to check the value of the automatic macro variable
SYSERR.
For more information and syntax of the %SYSRPUT statement, see “%SYSRPUT
Statement” on page 342.
Using %SYSLPUT with SAS/CONNECT
The %SYSLPUT statement is a macro statement that is submitted in the client session to
assign a value that is available in the client session to a macro variable that can be
accessed from the server session. If you are signed on to multiple server sessions,
%SYSLPUT submits the macro assignment statement to the most recently used server
session. If you are signed on to only one server session, %SYSLPUT submits the macro
assignment statement to that server session. If you are not signed on to any session, an
error condition results. Like the %LET statement, the %SYSLPUT statement assigns a
value to a macro variable. Unlike %LET, the %SYSRPUT statement assigns a value to a
variable in the server session rather than in the client session where the statement is
executed. The %SYSRPUT statement stores the macro variable in the Global Symbol
Table in the server session.
For more information about using %SYSLPUT, see “The %SYSLPUT and %SYSRPUT
Statements” in SAS/CONNECT Users Guide.
Example Using %SYSLPUT
%SYSLPUT enables you to dynamically assign values to variables that are used by
macros that are executed in a server session. The macro statement %SYSLPUT is used
to create the macro variable REMID in the server session and to use the value of the
client macro variable RUNID. The REMID variable is used by the %DOLIB macro,
which is executed in a server session. This process finds out which operating system-
specific library assignment should be used in the server session.
%macro assignlib (runid);
signon rem &runid
%syslput remid=&runid
rsubmit rem &runid
%macro dolib;
%if (&runid eq 1) %then %do;
libname mylib 'h:';
%end;
%else %if (&runid eq 2) %then %do;
libname mylib '/afs/some/unix/path';
%end;
%mend;
%dolib;
endrsubmit;
%mend;
114 Chapter 8 Interfaces with the Macro Facility
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset