Your macro does not create any code, so your condition ends up as
myFld1 IN ()
Hi,
1) you have a semicolon in the end `&emit;` make it . or
2) maybe this approach will help:
%macro CatPrompt (prmpt);
%local i emit _dlm _count _prmpt;
%let emit = "NOT-EXISTING-VALUE"; /* workaround for empty list */
%if %bquote(&prmpt.) NE %then
%do;
%LET emit = ;
%LET _dlm = ;
%LET _count = %QSYSFUNC(COUNTW(&prmpt.));
%do i = 1 %to &_count;
%LET _prmpt = %QSCAN(&prmpt., &i.);
%let emit = &emit.&_dlm. %SYSFUNC(quote(&_prmpt.));
%if &i. = 1 %then %LET _dlm =,;
%end;
%end;
&emit.
%mend CatPrompt;
%put *%CatPrompt(prmpt)*; /*single element list */
%put *%CatPrompt(A'A B'B C"C D"D E)*; /* multiple elements list with quotes in it */
%put *%CatPrompt()*; /* empty list */
%let list = a b c d;
%put *%CatPrompt(&list.)*; /* list in a macrovariable */
All the best
Bart
I assume you have macro variables like this:
%let a1=James;
%let a2=Anna;
%let a3=Culbert;
%let a_count=3;
And you want to do something like this:
proc sql;
select name from sashelp.class where name in(%catprompt(a));
quit;
There seems to be some sort of macro quoting problem, meaning that the stuff in the IN clause does not resolve correctly. I was too lazy to find out what it was, so I just wrote a new version of the macro without quoting (the %STR gets unquoted by the %SYSFUNC):
%macro CatPrompt(prmpt);
%local i delim;
%do i=1 %to &&&prmpt._count;
%do;&delim.%sysfunc(quote(&&&prmpt&i,%str(%')))%end;
%let delim=,;
%end;
%mend;
and that seems to work as intended.
The inner %DO...%END is just to avoid spurious whitespace in the output.
Edit added:
When you have input from users (they are unpredictable!) you may want to make sure that they do not break your precious macro by typing strange characters in the wrong places. So I did another version of the macro, getting the variable values using %SUPERQ (the macro quoting by %SUPERQ also gets neutralized by %SYSFUNC, and the QUOTE function makes sure that the quotes are balanced):
%macro CatPrompt(prmpt);
%local i delim;
%do i=1 %to &&&prmpt._count;
%do;&delim.%sysfunc(quote(%superq(&prmpt.&i),%str(%')))%end;
%let delim=,;
%end;
%mend;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.