Using macro in rsubmit

Reply
Contributor
Posts: 71

Using macro in rsubmit

Hello Group,

 

I am not a expert macro user so i need some help here. I am trying to run the below macro code in Rsubmit(SASGRID environment) and it's throwing the following error at me "ERROR: All positional parameters must precede keyword parameters". But when I run the same code outside Rsubmit it works fine. The logic here is to run the code inside rsubmit only on Tuesday's and Thursday's.

Can someone explain me what I am doing wrong here? I wonder why it is failing only when i try to run inside the rsubmit. Is it something to do with macro compilation? Thank you in advance for your time!

 

Below is my code:

 

%remote_signon;


%Macro statechk;

%if %sysfunc(weekday(%sysfunc(today()))) = 4 or %sysfunc(weekday(%sysfunc(today()))) = 6 %then
%do;

rsubmit;
options mprint;


%macro check (state,city);

Data CA_Stat;
Set maps.uscity
%if &state ne %str( ) %then (where=(&state.));
;
if city = "&city";
run;
%mend;


%check(%str(statecode = 'CA'),Irvine);


endrsubmit;

%end;
%Mend;
%statechk
;

 

Log:

 

%Macro statechk;
47
48 %if %sysfunc(weekday(%sysfunc(today()))) = 4 or %sysfunc(weekday(%sysfunc(today()))) = 6 %then
49 %do;
50
51 rsubmit;
52 options mprint;
53
54
55 %macro check (state,city);
56
57 Data CA_Stat;
58 Set maps.uscity
59 %if &state ne %str( ) %then (where=(&state.));
60 ;
61 if city = "&city";
62 run;
63 %mend;
64
65
66 %check(%str(statecode = 'CA'),Irvine);
67
68
69 endrsubmit;
70
71 %end;
72 %Mend;
73
74 %statechk
MACROGEN(STATECHK): rsubmit
NOTE: Remote submit to GRID commencing.
MACROGEN(STATECHK): ; options mprint;
MACROGEN(STATECHK): %macro check (state,city);
MACROGEN(STATECHK): Data CA_Stat;
MACROGEN(STATECHK): Set maps.uscity %if &state ne %then (where=(&state.));
MACROGEN(STATECHK): ;
MACROGEN(STATECHK): if city = "&city";
MACROGEN(STATECHK): run;
MACROGEN(STATECHK): %mend;
MACROGEN(STATECHK): %check(statecode = 'CA',Irvine);
MACROGEN(STATECHK): endrsubmit;
1 options mprint;
2 %macro check (state,city);
3 Data CA_Stat;
4 Set maps.uscity %if &state ne %then (where=(&state.));
5 ;
6 if city = "&city";
7 run;
8 %mend;
9 %check(statecode = 'CA',Irvine);
ERROR: All positional parameters must precede keyword parameters.
NOTE: Remote submit to GRID complete.
75 ;

 

Super User
Posts: 17,734

Re: Using macro in rsubmit

In my experience having an RSUBMIT inside a macro generates unexpected behaviour. I found that redesigning my programs to run entirely on the server was the best option.

 

If you try and run this code on the server as well, you're asking it to do an RSUBMIT, but its already connected to the server so it will generate an error. 

Contributor
Posts: 71

Re: Using macro in rsubmit

I just changed the code a bit. I moved the rsubmit to the top and wrapped the macro inside rsubmit and it works fine!. So  is it an issue with how we use Rsubmit with macro in general?

 


rsubmit;
%Macro statechk;

%if %sysfunc(weekday(%sysfunc(today()))) = 4 or %sysfunc(weekday(%sysfunc(today()))) = 6 %then
%do;


options mprint;


%macro check (state,city);

Data CA_Stat;
Set maps.uscity
%if &state ne %str( ) %then (where=(&state.));
;
if city = "&city";
run;
%mend;


%check(%str(statecode = 'CA'),Irvine);

 

%end;
%Mend;

%statechk
;

endrsubmit;

Super User
Posts: 17,734

Re: Using macro in rsubmit

I think it was the issue of you were already connected to the server and trying to use RSUBMIT on the server won't work. So your code would work on your desktop but the same process cannot work on the server. It may be possible to add a conditional check to see where your process is running and use the RSUBMIT only when required.

Super User
Super User
Posts: 6,495

Re: Using macro in rsubmit

[ Edited ]

Yes. The timing of when the macro triggers are executed is very confusing when you are using RSBUMIT blocks inside of a macro.

 

If you reference a macro variable or call a macro is that going to happen on the local machine and then the resulting generated SAS code pushed to the remote machine?  Or is the macro call going to be pushed to the remote machine so that it is resolved on the remote machine?  

 

Also if you nest a macro defintion inside of a macro you are running on your machine then the parsing of the lines can get confused by the need to push the lines to the remote machine in blocks.  This where the myth that you cannot use statement style comments ( *....; ) inside of macros comes from.

 

So if you want to define a macro on the remote machine then compile it from a file that already exists on the remote machine by either use %include or using SASAUTO macros. Or perhaps push the code to the remote machine as a text file and then rsubmit a %INCLUDE statement to pull in the text on the remote machine.

 

 

Contributor
Posts: 71

Re: Using macro in rsubmit

The %include option makes sense. To asnwer your question, though I am not entirely sure i think the later is happening. The macro is pushed to the remote server and excuted on the remote machine.

Ask a Question
Discussion stats
  • 5 replies
  • 116 views
  • 0 likes
  • 3 in conversation