DATA Step, Macro, Functions and more

SAS/CONNECT Macro Execution

Reply
Occasional Contributor
Posts: 10

SAS/CONNECT Macro Execution

Hi All,

I've been doing some work which involves submitted rsubmit commands through a local macro. I've re-read the excellent paper from SAS explaining the matter (The Relationship between SAS/CONNECT and the MACRO Facility), but I have an outstanding question:

When I run the following code, everything works as expected:

[pre]%macro m;
%let n = L;
%put &n;
%syslput n = R; /* 1 */
rsubmit; /* 2 */
%nrstr(%put &n.);
endrsubmit;
%mend m;
%m;[/pre]
&n resolves to L when checked locally, and R when checked remotely.

If I swap rsubmit and %syslput lines (marked 1 and 2) however ...
[pre]%macro m;
%let n = L;
%put &n;
rsubmit; /* 2 */
%syslput n = R; /* 1 */
%nrstr(%put &n.);
endrsubmit;
%mend m;
%m;[/pre]
... &n is no longer assigned a value on the remote host.

It seems to me that since the %syslput statement is exectuted in the local session, and that it would be available to the following %nrstr(%put) line, but apparently not!

I assume I'm missing something about either the compile/execution order or the interaction between rsubmit and the rest of the macro.

Could some kind soul explain just what I've missed?

Thanks,
-- Will
Occasional Contributor
Posts: 9

Re: SAS/CONNECT Macro Execution

%SYSLPUT must be used PRIOR to an RSUBMIT. If you want to set a macro var local to the RSUBMIT session do a %LET between RSUBMIT ... ENDRSUBMIT.

If you want to return a macro var back to the local session use a %SYSRPUT betweeen RSUBMIT ... ENDRSUBMIT.

This assumes a single remote session else you can use %SYSLPUT var / remote = sessionid
Occasional Contributor
Posts: 10

Re: SAS/CONNECT Macro Execution

Thanks for your response tbellmer, but I don't think that's the issue (to be clear I am trying to load the macro variable from the local host to the remote host).

There aren't any errors when the code is executed, and I'd expect to see the following error if the remote host (there's only one) had tried to execute the %syslput:
[pre]ERROR: A link must be established by executing the SIGNON command before you can communicate with UNKNOWN.[/pre]

The paper I linked in the original post suggests using the mprint and mlogic options to identify which statements are executing locally, and which are executing remotely. mlogic lines are handled locally, and mprint lines as passed to the remote host.

Running the above code with these options in place gives the following:
[pre]NOTE: The macro M completed compilation without errors.
9 instructions 184 bytes.
36232 %m;
MLOGIC(M): Beginning execution.
MLOGIC(M): %LET (variable name is N)
MLOGIC(M): %PUT &n
L
MPRINT(M): rsubmit
NOTE: Remote submit to UAT1 commencing.
MLOGIC(M): %SYSLPUT (variable name is N)
MPRINT(M): ; %put &n;
MPRINT(M): endrsubmit;
WARNING: Apparent symbolic reference N not resolved.
142 %put &n;
&n
NOTE: Remote submit to UAT1 complete.
MLOGIC(M): Ending execution.[/pre]

The %syslput lines is mprinted, and as such I'd expect it to execute locally.

As it turns out, it doesn't seem to do anything. &n is not modified on either the local or remote hosts (I tried making &n global on both machines, but that didn't help), and no note, warning or error is given.
Respected Advisor
Posts: 3,887

Re: SAS/CONNECT Macro Execution

Hi Will

You sure agree that under normal circumstances one wouldn't code a %syslput within the rsubmit block.

I could imagine that %syslput is writing to some sort of pipe which is read by rsubmit - and that this pipe is empty as %syslput executes after rsubmit in your example. At least the sequence of log messages indicates this.

To test the theory: You could execute a second rsubmit block and check if &n is known there.

%macro m;
%let n = L;
%put &n;

rsubmit; /* 2 */
%syslput n = R; /* 1 */
endrsubmit;

rsubmit; /* 2 */
%nrstr(%put &n.);
endrsubmit;
%mend m;
%m;

Can't test it in the moment. Please let me know the result.

Cheers
Patrick
Occasional Contributor
Posts: 10

Re: SAS/CONNECT Macro Execution

Hi Patrick,

No joy with seeing an updated value in a second rsubmit either:
[pre]NOTE: The macro M completed compilation without errors.
9 instructions 196 bytes.
36341 %m;
MLOGIC(M): Beginning execution.
MLOGIC(M): %LET (variable name is N)
MLOGIC(M): %PUT &n
L
MPRINT(M): rsubmit
NOTE: Remote submit to UAT1 commencing.
MLOGIC(M): %SYSLPUT (variable name is N)
MPRINT(M): ; endrsubmit;
NOTE: Remote submit to UAT1 complete.
MPRINT(M): rsubmit
NOTE: Remote submit to UAT1 commencing.
MPRINT(M): ; %put &n.;
MPRINT(M): endrsubmit;
WARNING: Apparent symbolic reference N not resolved.
162 %put &n.;
&n.
NOTE: Remote submit to UAT1 complete.
MLOGIC(M): Ending execution.[/pre]

The result of the %syslput line seems to be getting lost in the ether somewhere! Message was edited by: WillDobson
Occasional Contributor
Posts: 10

Re: SAS/CONNECT Macro Execution

Does anybody have any more ideas on this? I've still not found an answer!
SAS Employee
Posts: 58

Re: SAS/CONNECT Macro Execution

What version of SAS are you running?
Occasional Contributor
Posts: 10

Re: SAS/CONNECT Macro Execution

Base SAS 9.1.3
Super User
Posts: 3,102

Re: SAS/CONNECT Macro Execution

Going back to your original post if you want macro var N to be defined in both local and remote sessions in your second example you need to change your code from:

%macro m;
%let n = L;
%put &n;
rsubmit; /* 2 */
%syslput n = R; /* 1 */
%nrstr(%put &n.);
endrsubmit;
%mend m;
%m;

to this:

%macro m;
%let n = L;
%put &n;
rsubmit; /* 2 */
%let n = R;
%syslput n = &n; /* 1 */
%nrstr(%put &n.);
endrsubmit;
%mend m;
%m;

In your example you never create N in the remote session, but instead the %SYSLPUT in your RSUBMIT creates it back on your local session.
Occasional Contributor
Posts: 10

Re: SAS/CONNECT Macro Execution

Hi SASKiwi, thanks for your response.

Running your suggestion still gives the same problem however, &n. is undefined on the remote host:
[pre]
1663 %macro m;
1664 %let n = L;
1665 %put &n;
1666 rsubmit; /* 2 */
1667 %let n = R;
1668 %syslput n = &n; /* 1 */
1669 %nrstr(%put &n.);
1670 endrsubmit;
1671 %mend m;
NOTE: The macro M completed compilation without errors.
11 instructions 216 bytes.
1672 %m;
MLOGIC(M): Beginning execution.
MLOGIC(M): %LET (variable name is N)
MLOGIC(M): %PUT &n
L
MPRINT(M): rsubmit
NOTE: Remote submit to DEV1 commencing.
MLOGIC(M): %LET (variable name is N)
MLOGIC(M): %SYSLPUT (variable name is N)
MPRINT(M): ; %put &n.;
MPRINT(M): endrsubmit;
WARNING: Apparent symbolic reference N not resolved.
142 %put &n.;
&n.
NOTE: Remote submit to DEV1 complete.
MLOGIC(M): Ending execution.
[/pre]

In reference to my iniital example, my understanding is that %syslput would create the variable on the remote host (and that it's just as happy to do that with a plain string as it is with another macro variables).
Valued Guide
Posts: 2,174

Re: SAS/CONNECT Macro Execution

See http://support.sas.com/kb/23/986.html
It explains "In this example, the %LET that creates the macro variable X is COMPILED CODE and is executed on the local host, whereas the reference to the macro variable is TEXT and is executed on the remote host. " and provides a solution, which I leave you to read to ensure the whole picture is appreciated.

peterC
Occasional Contributor
Posts: 10

Re: SAS/CONNECT Macro Execution

Thanks for the link Peter.C. I took a look at the article, and the further reading link it contains (also linked in the OP), and it seems to confirm my current understanding of how things work.

I suspect I'm missing something glaringly obvious here, but in the OP I don't use %let to try to assign a remote variable, I use %syslput.
%syslput should (I think) be compiled code, and it should execute on the local host (just like the %let in the article you linked).
I've included mprint and mlogic in the logs I posted, and that suggests that %syslput is being executed on the local host (it is MLOGIC annotated).

Which brings me back to the question from the OP, why, when %syslput is seemingly executed on the local host, is the remote macro variable not assigned?
Valued Guide
Posts: 2,174

Re: SAS/CONNECT Macro Execution

Compiled code is stored in a macro catalog. It can be re-invoked without re-compiling. I suspect the code compiled on the client, does not establish anything on the server until it runs by which stage the syslput is getting lost. Not sure if it is a defect.
I would stick to keeping the syslput in the client session, since that seems to do all you need.
peterC
Ask a Question
Discussion stats
  • 12 replies
  • 1609 views
  • 0 likes
  • 6 in conversation