DATA Step, Macro, Functions and more

Macro Variable holding "ENDRSUBMIT;" returns 'Statement not valid or used out of proper order'

Accepted Solution Solved
Reply
Contributor
Posts: 63
Accepted Solution

Macro Variable holding "ENDRSUBMIT;" returns 'Statement not valid or used out of proper order'

I have a need to move a series of programs from Windows to Linux and maintain them in both environments.  I want to maintain only one copy of the code however.

 

When running in Windows the programs use rsubmit-endrsubmit to execute code on the Linux server.  So to maintain a single copy of the code I need to have those rsubmit-endrsubmit statements execute only when the environment is Windows.  To do this I'm assigning 'rsubmit' and 'endrsubmit' as values to macro variables named &_rsubmit and &_endrsubmit.

 

As the program and log show, under Windows the &_rsubmit works properly but &_endrsubmit returns the 'Statement not valid or used out of proper order' error.  You'll see that I've used &syslput to move the value of &_endrsubmit to the server, thinking that perhaps the endrsubmit must be issued there, but the error is still returned. 

 

I need the endrsubmit statement because when the code executes in Windows often there's a DATA Step or Proc SQL following the code that executes on the Linux server.  The log shows the error is causing the second DATA Step to execute on Linux but it should execute in Windows.

 

I suspect the problem has something to do with macro quoting.  Symbolgen produces a message about quoting.  I have to use %str() to get the ; included as part of the resolved value.

 

Using SAS 9.4 M2 on both Windows and Linux 64.  Suggestions will be appreciated.  Thanks.

 

John Bentley

CODE--

%put os= &sysscp; %let _serverAlias=SASGRID; %macro assignRsubEndRsub; %** Initialize macro variables as Global. ; %global _rsubmit _endrsubmit; %** Assign macro vars based on &sysscp value.; %if &sysscp=WIN %then %do; %let _rsubmit=%str(RSUBMIT &_serverAlias;); %let _endrsubmit=%str(ENDRSUBMIT;); %** move _endrsubmit to server. Needed there? ; %syslput _endrsubmit=&_endrsubmit; %end; %else %if &sysscp=%str(LIN X64) %then %do; %let _rsubmit=%str( ); %let _endrsubmit=%str( ); %end; %else %do; %let _rsubmit=%str(Unsupported OS); %let _endrsubmit=%str(Unsupported OS); %end; %mend; %assignRsubEndRsub; %put _rsubmit= &_rsubmit; %put _endrsubmit= &_endrsubmit; &_rsubmit; data _null_; run; &_endrsubmit; data _null_; run;

LOG--

393 %put os= &sysscp; SYMBOLGEN: Macro variable SYSSCP resolves to WIN os= WIN 394 395 %let _serverAlias=SASGRID; 396 397 %macro assignRsubEndRsub; 398 %** Initialize macro variables as Global. ; 399 %global _rsubmit _endrsubmit; 400 401 %** Assign macro vars based on &sysscp value.; 402 %if &sysscp=WIN %then %do; 403 %let _rsubmit=%str(RSUBMIT &_serverAlias;); 404 %let _endrsubmit=%str(ENDRSUBMIT;); 405 406 %** move _endrsubmit to server. Needed there? ; 407 %syslput _endrsubmit=&_endrsubmit; 408 %end; 409 %else %if &sysscp=%str(LIN X64) %then %do; 410 %let _rsubmit=%str( ); 411 %let _endrsubmit=%str( ); 412 %end; 413 %else %do; 414 %let _rsubmit=%str(Unsupported OS); 415 %let _endrsubmit=%str(Unsupported OS); 416 %end; 417 418 %mend; 419 420 %assignRsubEndRsub; 421 422 %put _rsubmit= &_rsubmit; _rsubmit= RSUBMIT SASGRID; 423 %put _endrsubmit= &_endrsubmit; SYMBOLGEN: Macro variable _ENDRSUBMIT resolves to ENDRSUBMIT; SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing. _endrsubmit= ENDRSUBMIT; 424 425 options symbolgen; 426 427 &_rsubmit; SYMBOLGEN: Macro variable _RSUBMIT resolves to RSUBMIT SASGRID; SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing. NOTE: Remote submit to SASGRID commencing. 75 data _null_; 76 run; NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds SYMBOLGEN: Macro variable _ENDRSUBMIT resolves to ENDRSUBMIT; SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing. 77 &_endrsubmit; NOTE: Line generated by the macro variable "_ENDRSUBMIT". 77 ENDRSUBMIT; ---------- 180 ERROR 180-322: Statement is not valid or it is used out of proper order. 78 79 options nosymbolgen; 80 81 data _null_; 82 run; NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds NOTE: Remote submit to SASGRID complete.

Accepted Solutions
Solution
‎06-05-2017 05:43 PM
Super User
Super User
Posts: 6,499

Re: Macro Variable holding "ENDRSUBMIT;" returns 'Statement not valid or used out of prope

It is hard to fool the SAS processor into doing what you want.

What I have found is that if you are running a macro locally you can conditionally generate the RSUBMIT/ENDRSUBMIT statements.  But you will see a site effect that macro variables as run locally instead of remotely.  Which might be what you want any way?

%macro run_both(x);
  %if "&x"="WIN" %then %do; rsubmit; %end;
   %put &=x ;
   %put &=mvar ;
  %if "&x"="WIN" %then %do; endrsubmit; %end;
%mend run_both;

signon test1 sascmd='!sascmd';
%let mvar=LOCAL;
%syslput mvar=REMOTE;

* No macro at all ;
rsubmit;
   %put &=mvar ;
endrsubmit;

* Macro call without rsubmit;
%run_both(xxx);
* Macro call with rsubmit;
%run_both(WIN);
signoff;

Results

NOTE: Remote signon to TEST1 complete.
3161  %let mvar=LOCAL;
3162  %syslput mvar=REMOTE;
3163
3164  * No macro at all ;
3165  rsubmit;
NOTE: Remote submit to TEST1 commencing.
1       %put &=mvar ;
MVAR=REMOTE
NOTE: Remote submit to TEST1 complete.
3166
3167  * Macro call without rsubmit;
3168  %run_both(xxx);
X=xxx
MVAR=LOCAL
3169  * Macro call with rsubmit;
3170  %run_both(WIN);
MPRINT(RUN_BOTH):   rsubmit
NOTE: Remote submit to TEST1 commencing.
X=WIN
MVAR=LOCAL
MPRINT(RUN_BOTH):  ; endrsubmit;
NOTE: Remote submit to TEST1 complete.
3171  signoff;
NOTE: Remote signoff from TEST1 commencing

View solution in original post


All Replies
Super User
Super User
Posts: 6,499

Re: Macro Variable holding "ENDRSUBMIT;" returns 'Statement not valid or used out of prope

Why are you macro quoting the macro variable? Why are you including the semi-colon in the value of macro variable?  

Don't do that.

 

But I think the real logic problem is this statement in the first macro:

%** move _endrsubmit to server.  Needed there? ;
%syslput _endrsubmit=&_endrsubmit;

The RSUBMIT/ENDRSUBMIT statements are run on LOCAL server to mark the block of code that is to be rsubmitted.  If you run an ENDRSUBMIT in the block of code that is running remotely it will try to end the block of code that it is submitting to some third SAS session on some other server.

Solution
‎06-05-2017 05:43 PM
Super User
Super User
Posts: 6,499

Re: Macro Variable holding "ENDRSUBMIT;" returns 'Statement not valid or used out of prope

It is hard to fool the SAS processor into doing what you want.

What I have found is that if you are running a macro locally you can conditionally generate the RSUBMIT/ENDRSUBMIT statements.  But you will see a site effect that macro variables as run locally instead of remotely.  Which might be what you want any way?

%macro run_both(x);
  %if "&x"="WIN" %then %do; rsubmit; %end;
   %put &=x ;
   %put &=mvar ;
  %if "&x"="WIN" %then %do; endrsubmit; %end;
%mend run_both;

signon test1 sascmd='!sascmd';
%let mvar=LOCAL;
%syslput mvar=REMOTE;

* No macro at all ;
rsubmit;
   %put &=mvar ;
endrsubmit;

* Macro call without rsubmit;
%run_both(xxx);
* Macro call with rsubmit;
%run_both(WIN);
signoff;

Results

NOTE: Remote signon to TEST1 complete.
3161  %let mvar=LOCAL;
3162  %syslput mvar=REMOTE;
3163
3164  * No macro at all ;
3165  rsubmit;
NOTE: Remote submit to TEST1 commencing.
1       %put &=mvar ;
MVAR=REMOTE
NOTE: Remote submit to TEST1 complete.
3166
3167  * Macro call without rsubmit;
3168  %run_both(xxx);
X=xxx
MVAR=LOCAL
3169  * Macro call with rsubmit;
3170  %run_both(WIN);
MPRINT(RUN_BOTH):   rsubmit
NOTE: Remote submit to TEST1 commencing.
X=WIN
MVAR=LOCAL
MPRINT(RUN_BOTH):  ; endrsubmit;
NOTE: Remote submit to TEST1 complete.
3171  signoff;
NOTE: Remote signoff from TEST1 commencing
Contributor
Posts: 63

Re: Macro Variable holding "ENDRSUBMIT;" returns 'Statement not valid or used out of prope

Thanks for your reply Tom.  It gave me a starting point, and from it I've come up with this.  I can put the code that might execute locally into macros so that's not a problem.  But to make modifying the programs easier I'd like to convert the %if &sysscp=WIN %then %end into macro variables but can't seem to get it to work because of the special characters.  I'll tinker with the quoting functions a bit more.

options symbolgen;

/*rsubmit;*/
%macro testit;
	%put &=sysscp;

	%if &sysscp=WIN %then %do; rsubmit; %end;
		data _null_;
			x=1;
		run;
	%if &sysscp=WIN %then %do; endrsubmit; %end;
%mend testit;

%testit;

options nosymbolgen;

data _null_;
run;
/*endrsubmit;*/
☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 120 views
  • 0 likes
  • 2 in conversation