DATA Step, Macro, Functions and more

Proc SQL within Macro error

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Proc SQL within Macro error

I'm trying to run some proc sql within a macro and SAS won't recognise my macro variables.  What am I doing wrong...

 

%macro sixmonthroll(startdate,longstart,longend);

rsubmit;

proc sql;

create table &startdate. as

etc.

etc.

quit;

endrsubmit;

%sixmonthroll (jan16,jan_2016,jul_2016);

 

When I run the code above I get the following error:

 

224 %sixmonthroll (jan16,jan_2016,jul_2016);

NOTE: Remote submit to HOST commencing.

491 proc sql;

492 create table &startdate. as select

                 -

                 22

                 200

 

WARNING: Apparent symbolic reference STARTDATE not resolved.

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string.

 

 

 

 


Accepted Solutions
Solution
‎11-14-2016 10:54 AM
Super User
Posts: 7,863

Re: Proc SQL within Macro error


cstanyer wrote:
Could I move the rsubmits from within the macro code and rsubmit the %sixmonthroll instead?

That would only work if you also defined the macro remotely:

rsubmit;
%macro testmac(parameters);
/* statements */
%mend;
%testmac(params);
endrsubmit;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 7,863

Re: Proc SQL within Macro error

You will need to use the %syslput macro statement to transfer the values to the remote session.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 4

Re: Proc SQL within Macro error

Posted in reply to KurtBremser

 I wondered if it was something to do with that.  I've not used %syslput before- I'll look into it, thank you.

Super User
Posts: 7,863

Re: Proc SQL within Macro error

While macro statements like %let or %put or %if...%then...%else are executed locally, macro variable references are transferred to the remote session "as is" and resolved there, so one needs to create the macro variables in the remote session before using them.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 4

Re: Proc SQL within Macro error

Posted in reply to KurtBremser
Could I move the rsubmits from within the macro code and rsubmit the %sixmonthroll instead?
Solution
‎11-14-2016 10:54 AM
Super User
Posts: 7,863

Re: Proc SQL within Macro error


cstanyer wrote:
Could I move the rsubmits from within the macro code and rsubmit the %sixmonthroll instead?

That would only work if you also defined the macro remotely:

rsubmit;
%macro testmac(parameters);
/* statements */
%mend;
%testmac(params);
endrsubmit;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 4

Re: Proc SQL within Macro error

Posted in reply to KurtBremser

That's what I did.  Thanks for the help!

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 264 views
  • 0 likes
  • 2 in conversation