/* begin container macro */ %MACRO macro-name; RSUBMIT; statements ENDRSUBMIT; %mend macro-name; /* end container macro */ %macro-name
%global star slash;
%let star=*;
%let slash=/;
&star rsubmit;
data x; x=1; run;
&slash&star endrsubmit; /* */
&slash&star signoff; /* *//* In this macro, %LET is a macro statement that will be interpreted */ /* by the client session and not submitted remotely. */ /* If REMVAR1 is not already defined in the server session, */ /* this example will produce an error. */ %macro example; %global remvar1; rsubmit; data x; x=1; run; %let remvar1=%sysfunc(date(),date9.); data a; x="&remvar1"; run; endrsubmit; %mend; %example;
/* In this macro, the %SYSLPUT statement is used to assign a value to a */ /* macro variable in the server session, to avoid having the client session */ /* macro processor interpret a %LET statement in the RSUBMIT block. */ /* %SYSLPUT can also be issued outside the macro definition. */ %macro example1; %syslput remvar1=&sysfunc(date(),date9.); rsubmit; data a; x="&remvar1"; run; endrsubmit; %mend; %example1;
/* This shows a macro definition embedded in an RSUBMIT block.
*/
/* The entire ONREMOTE macro definition is remotely submitted */
/* and none of the statements in the ONREMOTE macro are interpreted */
/* by the macro processor in the client session. */
%macro example3;
rsubmit;
%macro onremote;
%global abc;
%put this is on the server;
%let abc=value;
%mend;
%onremote;
endrsubmit;
%mend;
%example3;/* In this macro example, %IF is interpreted by the */
/* macro processor in the client session in order to determine */
/* whether to execute PROC DOWNLOAD. */
%macro example4;
%global localvar2;
rsubmit;
data remds;
x=1;
run;
%if &localvar2 eq getit %then %do;
proc download;
run;
%end;
endrsubmit;
%mend;
%let localvar2=getit;
%example4; /* download occurs */
%let localvar2=;
%example4; /* download does not occur *//* The following macro shows how embedded macros work. The */
/* %PUT statements indicate where the macros are defined and */
/* where they should be invoked. */
/* The macro ONREMOTE is defined to the server session because it */
/* is in an RSUBMIT/ENDRSUBMIT block. Therefore, its invocation */
/* must be remotely submitted. The macro ONLOCAL is defined to */
/* the client session and its invocation is locally submitted. */
%macro embeddedmacros;
rsubmit;
%macro onremote;
%put on the remote side;
%mend;
endrsubmit;
%macro onlocal;
%put on the local side;
%mend;
rsubmit;
%onremote;
endrsubmit;
%onlocal;
%mend;
%embeddedmacros;/* This macro shows that everything in the RSUBMIT/ENDRSUBMIT block */ /* is executed by the server session because there are no macro */ /* statements in the macro-generated RSUBMIT to be interpreted by */ /* the macro processor in the client session. */ %macro do-x; rsubmit; data x; date="04 July 03"; put date=; run; endrsubmit; %mend; %do-x;
/* This macro uses SYMPUT in an RSUBMIT, and */
/* uses %NRSTR to "hide" the %PUT statement from the macro processor */
/* in the client session, so that it can be executed by the */
/* server session. */
%macro nullds;
rsubmit;
data _null_;
call symput('abc','abc');
call symput('one','1');
call symput('date',"%sysfunc(date(),date9.)");
run;
%nrstr(%%)put abc=&abc one=&one date=&date;
endrsubmit;
%mend;
%nullds;%macro remotesysfunc;
rsubmit;
%nrstr(%%)let current="%sysfunc(time(),time.)";
%nrstr(%%)put current=¤t;
endrsubmit;
%mend;
%remotesysfunc;%put %sysfunc(getoption(connectremote));or
proc options option=connectremote; run;
unixhost, but you want to define the macro for your Windows computer winhost: %syslput currentds=ds2008/remote=winhost;As another example, two server sessions are created and the macro variable FLAG must be set in both sessions. The /REMOTE= option is used in the %SYSLPUT statements to direct the correct value to the correct server session.
signon task1 sascmd="sas"; signon task2 sascmd="sas"; %syslput flag=1/remote=task1; /* NOTE: Without the /REMOTE= option in the previous statement, the FLAG variable would be defined in the TASK2 session, because it was the session most recently accessed with the previous SIGNON statement. */ rsubmit task1; %put flag on task1 is &flag; endrsubmit; %syslput flag=2/remote=task2; /* NOTE: Without the /REMOTE= option in the previous statement, the FLAG variable would be defined in the TASK1 session, because it was the session most recently accessed with the previous RSUBMIT statement. */ rsubmit task2; %put flag on task2 is &flag endrsubmit;
RSUBMIT;
%MACRO MYDATE;
%PUT &SYSDATE;
%MEND MYDATE;
%MYDATE; /* must use semicolon here */
ENDRSUBMIT;%macro client;
RSUBMIT;
%let user1 = %sysget(LOGNAME);
%macro remote;
%global user2;
%let user2 = %sysget(LOGNAME);
%mend remote;
%remote
data _null_;
put "user 1 = &user1";
put " 2 = &user2";
run;
ENDRSUBMIT;
%mend client;
%clientApparent symbolic reference USER1 not resolved.
%MACRO SETPATH;
rsubmit;
%nrstr(%%let PATH1 = c:\winnt\system32%%str(;);)
%nrstr(%%let PATH2 = c:\winnt%%str(;);)
%nrstr(%%let PATH3 = c:\bin;)
%nrstr(%%let PATH = &PATH1.&PATH2&.&PATH3)
%nrstr(%%put PATH = &PATH)
endrsubmit;
%MEND;
%SETPATHNOTE: Remote submit to MAINPC commencing.
1 %let PATH1 = c:\winnt\system32%str(;
2 );
3 %let PATH2 = c:\winnt%str(;
4 );
5 %let PATH3 = c:\bin;
6 %let PATH = &PATH1.&PATH2&.&PATH3;
7 %put PATH = &PATH;
PATH = c:\winnt\system32; c:\winnt; c:\bin
NOTE: Remote submit to MAINPC complete.