I am having trouble calling a macro inside a SAS/CONNECT subsession with input parameters that are macro variables. I have %included the macro inside the subsession and confirm that it is being found when called. The issue comes with my use of macro variables inside the macro call (the &FILEIN and &FILEOUT parameters). I have created these inside the subsession and used put statements to confirm that they are resolving exactly as they should be. However, in the %winratio macro, I get an error that "Apparent symbolic reference to FILEIN not resolved" and the macro attempts to locate the dataset work.FILEIN. Is there a way to get this to work or am I going to have to hard code my macro calls?
%macro doover (REMRUN=,tm= ) ; %syslput _all_ / remote=task&REMRUN; /* Initialize child session */ rsubmit task&REMRUN wait=no inheritlib = (work=share); options symbolgen mprint mlogic; %include "/home/programs/macros/winratio.sas" ; %local T; %do T = %scan(&tm,1) %to %scan(&tm,-1) ; %put ERROR: &T; %let FILEIN = derived.adttwinratio_tm&T.; %let FILEOUT = share.unstratified&T.; %put &FILEIN; %winratio( idsn=&FILEIN , byvar=timen , tgrp=&RX1 , odsn = &FILEOUT ) ; %end ; /* End child session */ endrsubmit; %mend doover;
How can you send macro variables before you create the remote session? Do you really need to send every macro variable over? The only ones you appear to be using are TM and RX1. Where does the value of RX1 some from? It seems the code is expecting to magically have a value.
I suspect the %DO loop (if it is running at all) is running in your LOCAL session since you cannot use that statement in the open code you are running in the remote session.
Why not eliminate the macro logic in the remote session and avoid that confusion. Instead just use a data step running in the remote session to generate your macro calls.
%macro doover (REMRUN=,tm= ) ;
%local T;
/* Initialize child session */
rsubmit task&REMRUN inheritlib = (work=share);
options symbolgen mprint mlogic;
%include "/home/programs/macros/winratio.sas" ;
endrsubmit;
/* Send macro variables to remote */
%syslput tm=&tm / remote=task&REMRUN;
%syslput rx1=&rx1 / remote=task&REMRUN;
/* Run a series of %WINRATIO calls in the remote session */
rsubmit taks&REMRUN wait=no;
data _null_;
do t=%scan(&tm,1) to %scan(&tm,-1) ;
call execute(cats('%nrstr(%winratio)'
,'(idsn=derived.adttwinratio_tm',t
,',byvar=timen'
,',tgrp=&RX1'
,',odsn=share.unstratified',t
,')'
));
end;
run;
endrsubmit ;
%mend doover;
Hello @hartwell
Would you be able to paste the output from the log? Please turn on mprint and mlogic options before you run the code to capture the log.
Thanks,
Vj
How can you send macro variables before you create the remote session? Do you really need to send every macro variable over? The only ones you appear to be using are TM and RX1. Where does the value of RX1 some from? It seems the code is expecting to magically have a value.
I suspect the %DO loop (if it is running at all) is running in your LOCAL session since you cannot use that statement in the open code you are running in the remote session.
Why not eliminate the macro logic in the remote session and avoid that confusion. Instead just use a data step running in the remote session to generate your macro calls.
%macro doover (REMRUN=,tm= ) ;
%local T;
/* Initialize child session */
rsubmit task&REMRUN inheritlib = (work=share);
options symbolgen mprint mlogic;
%include "/home/programs/macros/winratio.sas" ;
endrsubmit;
/* Send macro variables to remote */
%syslput tm=&tm / remote=task&REMRUN;
%syslput rx1=&rx1 / remote=task&REMRUN;
/* Run a series of %WINRATIO calls in the remote session */
rsubmit taks&REMRUN wait=no;
data _null_;
do t=%scan(&tm,1) to %scan(&tm,-1) ;
call execute(cats('%nrstr(%winratio)'
,'(idsn=derived.adttwinratio_tm',t
,',byvar=timen'
,',tgrp=&RX1'
,',odsn=share.unstratified',t
,')'
));
end;
run;
endrsubmit ;
%mend doover;
Fantastic!
The %do was absolutely the issue. Thank you so much for catching that 😃 It's working beautifully now
To your other questions:
- The RX1 macro was created outside of the code snippet I included (it gets assigned in the autoexec)
- I definitely don't need to send all macro variables--I usually just start that way as I develop/troubleshoot.
- I've not had any issue sending macro variables to rsubmit sessions not yet created
You must have set your options for SAS so it will automatically spawn a new SAS session on your current machine/cluster.
Otherwise you would need to include SASCMD= option to spawn a local SAS session.
Or the other options that tell SAS/Connect how to find and connect to the actual remote server and launch SAS on it so you can make the remote connection.
But it is interesting to me that it would let you add the INHERITEDLIB= option AFTER it has already made the remote session.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.