How do I pass global variable to a remote macro to be run on a remote system using RSUBMIT.

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

How do I pass global variable to a remote macro to be run on a remote system using RSUBMIT.

[ Edited ]
I am trying to pass local environment variables to a macro that is executed on a 
remote server using rsubmit. In the local environment I create the global var definitions, 
then call the macro %NITC_Remote;  (the file is attached - and yes, i'm a novice).  
Thank you for your help. 


options mprint symbolgen mlogic
mautosource sasautos= ('H:\......\.....\Macros');  /*Location of Remote_macro*/

%macro gmacs;
%global molist yrlist sv;
%let mlist=03 06 09 12;
%let ylist=12 13 14 15 16 17;
%let sv=AS;
%mend gmacs;
%gmacs;

%NITC_Remote(&mlist,&ylist,&sv);

/*## MACRO CODE BEGINS HERE ##*/
%Macro NITC_Remote;
%let RTOT= H:/.../..../RTOT;
%syslput RTOT=&RTOT;

%let nitcspwn = 165.221.4.12 5423;
options comamid=tcp remote=nitcspwn nosource ;
signon username=_prompt_ password=_prompt_ ; /*OPENS SIGN ON PROMPT*/

rsubmit;
%nrstr(%let molist=&mlist;)
%nrstr(%let yrlist=&ylist;)
%nrstr(%let sv=&sv;)
%macro regloop(yrlist, molist, sv);
 %let s=1; %let t=1;
 %let cntyr=%sysfunc(countw(&yrlist));
 %let cntmo=%sysfunc(countw(&molist));
 
 %do s=1 %to &cntyr;
 %let yr=%scan(&yrlist,&s,%str( ));
 %do t=1 %to &cntmo;
 %let mo=%scan(&molist,&t,%str( ));

libname tots&yr.&mo. "NAP95&sv..&sv.US.D&yr.&mo.SUM.USRGN.SAS.DATA" disp=shr;
proc download data=tots&yr.&mo..rttots out=&RTOT.&sv._rttots&yr.&mo.;run;
 %end;%end;
%mend;
%regloop(&yrlist, &molist, &sv);

endrsubmit;

signoff;
%Mend NITC_Remote;
Attachment

Accepted Solutions
Solution
a week ago
Super User
Super User
Posts: 6,497

Re: How do I pass global variable to a remote macro to be run on a remote system using RSUBMIT.

[ Edited ]

You need to create the target libref on the local SAS session before running PROC DOWNLOAD on the remote session.

17 +proc download data=tots&yr.&mo..rttots out=RTOT.&sv._rttots&yr.&mo.;run;
...
NOTE: Libref TOTS1203 was successfully assigned as follows:
Engine: V9
Physical Name: NAP95AS.ASUS.D1203SUM.USRGN.SAS.DATA
ERROR: Libname RTOT is not assigned.
ERROR: Download function terminated.

So add a LIBNAME statement before the local macro call. Or if in the macro call then before the RSUBMIT/ENDRSUBMIT block.

libname RTOT "......";

Or if you meant to create a WORK dataset then remove the extra period from the OUT= value.

out=work.RTOT&sv._rttots&yr.&mo.

View solution in original post


All Replies
Regular Contributor
Posts: 213

Re: How do I pass global variable to a remote macro to be run on a remote system using RSUBMIT.

Hi,

Here is what listed in the SAS Online Help

"%SYSLPUT : Creates a new macro variable or modifies the value of an existing macro variable on a remote host or server.

To use %SYSLPUT, you must have initiated a link between a local SAS session or client and a remote SAS session or server using the SIGNON command or SIGNON statement. For more information, see the documentation for SAS/CONNECT software."

 

Basically, establish your connection first, via Signon statement, then from your local session, use %SYSLPUT to pass your global local macro variable(s) to the remote server.

 

Hope this helps,

Ahmed

Contributor
Posts: 30

Re: How do I pass global variable to a remote macro to be run on a remote system using RSUBMIT.

 

AhmedAl_Attar,  I have modified the macro language as follows.  The Log file is attached.  Still haveing trouble with the Libname statement.   Thank you. 

 

%Macro NITC_Remote;
%let RTOT= H:/...../...../...../RTOT;


%let nitcspwn = 165.221.4.12 5423;
options comamid=tcp remote=nitcspwn nosource ;
signon username=_prompt_ password=_prompt_ ;

%syslput RTOT=&RTOT;
%syslput molist=&molist;
%syslput yrlist=&yrlist;
%syslput sv=&sv;

rsubmit;
%macro regloop(yrlist, molist, sv);
%let s=1; %let t=1;
%let cntyr=%sysfunc(countw(&yrlist));
%let cntmo=%sysfunc(countw(&molist));

%do s=1 %to &cntyr;
%let yr=%scan(&yrlist,&s,%str( ));
%do t=1 %to &cntmo;
%let mo=%scan(&molist,&t,%str( ));

libname tots&yr.&mo. "NAP95&sv..&sv.US.D&yr.&mo.SUM.USRGN.SAS.DATA" disp=shr;
proc download data=tots&yr.&mo..rttots out=RTOT.&sv._rttots&yr.&mo.;run;
%end;%end;
%mend;
%regloop(&yrlist, &molist, &sv);

endrsubmit;

signoff;
%Mend NITC_Remote;

Super User
Super User
Posts: 6,497

Re: How do I pass global variable to a remote macro to be run on a remote system using RSUBMIT.

[ Edited ]

Use %SYSLPUT.  Change these lines

signon username=_prompt_ password=_prompt_ ;
rsubmit;
%nrstr(%let molist=&mlist;)
%nrstr(%let yrlist=&ylist;)
%nrstr(%let sv=&sv;)
...

To this instead.

signon username=_prompt_ password=_prompt_ ;
%syslput molist=&mlist;
%syslput yrlist=&ylist;
%syslput sv=&sv;
rsubmit;
...

If that has trouble because you are calling %SYSLPUT inside of a macro then you might want to revert to the method that SAS used before they made the %SYSLPUT statement.  Here is a version of the %SYSLPUT() macro that they had back in SAS 6.12, renamed to avoid conflict with the new %SYSLPUT statement.

%macro syslput612(macvar,macval,remote=);
   options nosource nonotes;
   %let str=%str(rsubmit &remote;options nosource;)
    %nrstr(%let) %str(&macvar = &macval;options source;endrsubmit;);
   &str; options notes source;
%mend syslput612;

 Code using macro.

signon username=_prompt_ password=_prompt_ ;
%syslput612(molist,&mlist)
%syslput612(yrlist,&ylist)
%syslput612(sv,&sv)
rsubmit;
...
Contributor
Posts: 30

Re: How do I pass global variable to a remote macro to be run on a remote system using RSUBMIT.

Tom, after I modified based on your first option (also suggested by Ahmed), that part of it worked (i think). Not there is a libname that does not assign. (see log attached).
Super User
Super User
Posts: 6,497

Re: How do I pass global variable to a remote macro to be run on a remote system using RSUBMIT.

Looks like the local macro is expanding some of the macro logic before pushing the generated macro definition to the remote session.

Can you take the remote macro defintion out of the local macro definition?

Or move it to the remote as text instead and then compile it?

%macro NITC_Remote;
%let RTOT= H:/...../...../...../RTOT;

%let nitcspwn = 165.221.4.12 5423;
options comamid=tcp remote=nitcspwn nosource ;
signon username=_prompt_ password=_prompt_ ;
%syslput RTOT=&RTOT;
%syslput molist=&molist;
%syslput yrlist=&yrlist;
%syslput sv=&sv;
rsubmit;
filename code temp;
data _null_;
  file code;
  put
  '%macro regloop(yrlist, molist, sv);'
 /'%let s=1; %let t=1;'
 /'%let cntyr=%sysfunc(countw(&yrlist));'
 /'%let cntmo=%sysfunc(countw(&molist));'
 /' '
 /'%do s=1 %to &cntyr;'
 /'%let yr=%scan(&yrlist,&s,%str( ));'
 /'%do t=1 %to &cntmo;'
 /'%let mo=%scan(&molist,&t,%str( ));'
 /'libname tots&yr.&mo. "NAP95&sv..&sv.US.D&yr.&mo.SUM.USRGN.SAS.DATA" disp=shr;'
 /'proc download data=tots&yr.&mo..rttots out=RTOT.&sv._rttots&yr.&mo.;run;'
 /'%end;%end;'
 /'%mend;'
  ;
run;
%include code / source2;
%regloop(&yrlist, &molist, &sv);
endrsubmit;
signoff;
%mend NITC_Remote;

 

Contributor
Posts: 30

Re: How do I pass global variable to a remote macro to be run on a remote system using RSUBMIT.


Tom, I see there is still a problem with the libname assignment. At least now it is recognizing the file names (with distinct months) and file size at the remote location.

 

Attached is the log file.  

 

...........
12 +%do s=1 %to &cntyr;
13 +%let yr=%scan(&yrlist,&s,%str( ));
14 +%do t=1 %to &cntmo;
15 +%let mo=%scan(&molist,&t,%str( ));
16 +libname tots&yr.&mo. "NAP95&sv..&sv.US.D&yr.&mo.SUM.USRGN.SAS.DATA" disp=shr;
17 +proc download data=tots&yr.&mo..rttots out=RTOT.&sv._rttots&yr.&mo.;run;
18 +%end;%end;
19 +%mend;
NOTE: %INCLUDE (level 1) ending.
20 %regloop(&yrlist, &molist, &sv);
NOTE: Libref TOTS1203 was successfully assigned as follows:
Engine: V9
Physical Name: NAP95AS.ASUS.D1203SUM.USRGN.SAS.DATA

ERROR: Libname RTOT is not assigned.
ERROR: Download function terminated. The data set created may be unusable.
NOTE: The data set TOTS1203.RTTOTS has 20181 observations and 40 variables.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: The PROCEDURE DOWNLOAD used 0.00 CPU seconds and 21901K.

NOTE: The address space has used a maximum of 980K below the line and 26192K above the line.

NOTE: Libref TOTS1206 was successfully assigned as follows:
Engine: V9
Physical Name: NAP95AS.ASUS.D1206SUM.USRGN.SAS.DATA

 

Attachment
Solution
a week ago
Super User
Super User
Posts: 6,497

Re: How do I pass global variable to a remote macro to be run on a remote system using RSUBMIT.

[ Edited ]

You need to create the target libref on the local SAS session before running PROC DOWNLOAD on the remote session.

17 +proc download data=tots&yr.&mo..rttots out=RTOT.&sv._rttots&yr.&mo.;run;
...
NOTE: Libref TOTS1203 was successfully assigned as follows:
Engine: V9
Physical Name: NAP95AS.ASUS.D1203SUM.USRGN.SAS.DATA
ERROR: Libname RTOT is not assigned.
ERROR: Download function terminated.

So add a LIBNAME statement before the local macro call. Or if in the macro call then before the RSUBMIT/ENDRSUBMIT block.

libname RTOT "......";

Or if you meant to create a WORK dataset then remove the extra period from the OUT= value.

out=work.RTOT&sv._rttots&yr.&mo.
Contributor
Posts: 30

Re: How do I pass global variable to a remote macro to be run on a remote system using RSUBMIT.

Tom, That works... so, now I realize we have two solutions. In the beginning, %nrstr() should have been used on the %let, %do, %if.


%let nitcspwn = 165.221.4.12 5423;
options comamid=tcp remote=nitcspwn nosource ;
signon username=_prompt_ password=_prompt_ ;


%syslput molist=&molist;
%syslput yrlist=&yrlist;
%syslput sv=&sv;

rsubmit;
%macro regloop(yrlist, molist, sv);
%nrstr(%let s=1Smiley Wink %nrstr(%let t=1Smiley Wink
%nrstr(%let cntyr=%sysfunc(countw(&yrlist))Smiley Wink
%nrstr(%let cntmo=%sysfunc(countw(&molist))Smiley Wink

%nrstr(%do s=1 %to &cntyrSmiley Wink
%nrstr(%let yr=%scan(&yrlist,&s,%str( ))Smiley Wink
%nrstr(%do t=1 %to &cntmoSmiley Wink
%nrstr(%let mo=%scan(&molist,&t,%str( ))Smiley Wink

libname tots&yr.&mo. "NAP95&sv..&sv.US.D&yr.&mo.SUM.USRGN.SAS.DATA" disp=shr;
proc download data=tots&yr.&mo..rttots out=RTOT.&sv._rttots&yr.&mo.;run;
%end;%end;
%mend;
%regloop(&yrlist, &molist, &sv);

endrsubmit;

signoff;
%Mend NITC_Remote;
Contributor
Posts: 30

Re: How do I pass global variable to a remote macro to be run on a remote system using RSUBMIT.

The second solution was not* using %syslput with %let for the libname. As you said, just put the libname as usual before the connect prompt.

%Macro NITC_Test3; /*Jacob Carter*/

libname RTOT "H:\Shared\MDSEIMB\SFDS\SDS\Green Book\RTOT";

%let nitcspwn = 165.xxx.4.xx xxxx;
options comamid=tcp remote=nitcspwn nosource ;
signon username=_prompt_ password=_prompt_ ;

%syslput molist=&molist;
%syslput yrlist=&yrlist;
%syslput sv=&sv;

rsubmit;filename code temp;
data _null_;
file code;
put
'%macro regloop(yrlist, molist, sv);'
/'%let s=1; %let t=1;'
/'%let cntyr=%sysfunc(countw(&yrlist));'
/'%let cntmo=%sysfunc(countw(&molist));'
/' '
/'%do s=1 %to &cntyr;'
/'%let yr=%scan(&yrlist,&s,%str( ));'
/'%do t=1 %to &cntmo;'
/'%let mo=%scan(&molist,&t,%str( ));'
/'libname tots&yr.&mo. "NAP95&sv..&sv.US.D&yr.&mo.SUM.USRGN.SAS.DATA" disp=shr;'
/'proc download data=tots&yr.&mo..rttots out=RTOT.&sv._rttots&yr.&mo.;run;'
/'%end;%end;'
/'%mend;'
;
run;
%include code / source2;
%regloop(&yrlist, &molist, &sv);
endrsubmit;
signoff;
%mend NITC_Test3;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 158 views
  • 0 likes
  • 3 in conversation