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.
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
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.
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
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;*/
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.