You can use %BQUOTE() to resolve macro logic inside of single quotes.
So let's do an example that does not overwrite its input.
Say you have these two macro variables that will work as dates in your SQL system (what SQL database uses dates in the style?)
%let SQL_start = '01JAN2007';
%let SQL_end = '30JUN2007';
You can make a new string in that style like this:
%bquote('%sysfunc(intnx(month,&sql_start.d,-1),date9.)')
If you want add your indirect references to the macro variables (why? what value is there in overcomplicating things like that?) then use something like:
%let P = SQL;
%let lag = -1;
%let new_start = %bquote('%sysfunc(intnx(month,&&&p._start.d,&lag),date9.)');
But perhaps it would be clearer to do it in steps?
%let olddate=&&&p._start.d;
%let newdate=%sysfunc(intnx(month,&olddate,&lag),date9.);
%let newdate=%bquote('&newdate');
If the macro quoting causes trouble (and it shouldn't in pass thru SQL code) then add a call to %unquote().
%let newdate=%unquote(&newdate);
Or perhaps use %SYSFUNC() to call QUOTE() to add the single quotes.
%let newdate=%sysfunc(quote(%sysfunc(intnx(month,&olddate,&lag),date9.),%str(%')));
... View more