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.
@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;
You will need to use the %syslput macro statement to transfer the values to the remote session.
I wondered if it was something to do with that. I've not used %syslput before- I'll look into it, thank you.
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.
@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;
That's what I did. Thanks for the help!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.