I wanted to iteratively pass list of variables in quotes separated by commas to a SQL WHERE “IN” clause
WHERE IDS in ('a111','a222','a333');
Please check below working piece of SAS macro code, first approach invokes macro directly using %, it is working as expected.
In the second approach; macro invocation using CALL EXECUTE, I am not able to pass multiple parameters without wrapping up in quotes
Else it will throw ERROR: More positional parameters found than defined
But as workaround I am able to remove the additional quote using a dequote inside the macro.
Can you suggest modification to CALL EXECUTE statement so that macro variable mbrlist receive values as 'a111','a222','a333' and not “'a111','a222','a333'”,
so that dequote statement is not needed, ie wrapping CALL executive parms or just macro parm with %NRSTR, %NRBQUOTE etc functions?
%macro get_dbdata(mbrlist) ;
%put &=mbrlist;
%let mbrlist_DQ=%sysfunc(dequote(&mbrlist.));
%put &=mbrlist_DQ;
%MEND;
/* 1. Call macro direct */
%let mbrlst='a111','a222','a333';
%put &=mbrlst;
%get_dbdata(%nrstr(&mbrlst));
/* 2. Call macro using Call execute */
data qq;
/* set indata; */
mbr_list="'b111','b222','b333'";
put mbr_list=;
call execute('%get_dbdata("' || strip(mbr_list) || '")' );;
run;
... View more