I think there are much easier approaches, that don't involve whether or not to use single quotes or double quotes or %UNQUOTE, so let me explain.
I think it is always better to work with dates as valid numeric SAS date values, rather than as character strings. This generally avoids the needs for single quotes and double quotes and %UNQUOTE. There are other reason to work with valid numeric SAS date values as well. And finally at the end of the program when human readable dates are needed, such as 30JUN2007, you format the date so it appears properly and in this case, add quotes around the date as required.
In this case:
%let P = P1;
/* Convert start date and end date to valid numeric SAS date values */
%let P1_start = %sysevalf('01JAN2007'd);
%let P1_end = %sysevalf('30JUN2007'd);
%put &=p1_start &=p1_end;
%let lag = -1;
/* Work with INTNX on valid SAS date values */
%let &P._start_l = %sysfunc(intnx(month, &&&p._start,&lag., same)) ;
%put &=p1_start_l;
%let SQL = WHERE date_var between %nrstr(%')%sysfunc(putn(&&&p._start_l,date9.))%nrstr(%') and %nrstr(%')%sysfunc(putn(&&&p._end,date9.))%nrstr(%') ;
%put &=sql;
So this approach, we no longer worry about putting dates into single quotes or double quotes and work with valid numeric SAS date values, and then at the end, we turn it back to something human readable as required by the problem.
I think also that there may be simpler approaches that don't involve &&& but you haven't shown us the whole macro, so we don't really know.
... View more