Hi...
First, you can't string your "OR" like that. Only these are valid: [pre]
If table.ethnic eq 'abc' or
table.ethnic eq 'def' or
table.ethnic eq 'ghi' or
table.ethnic eq 'jkl';
where table.ethnic eq 'abc' or
table.ethnic eq 'def' or
table.ethnic eq 'ghi' or
table.ethnic eq 'jkl';
where table.ethnic in ('abc', 'def', 'ghi', 'jkl');
[/pre]
So that's one problem. You don't really need superq for that first comparison when you are testing for the presence of the ðnicity parameter (see program). Also, if you REQUIRED them to make at least 1 selection then you would know that ETHNICITY would always have a value and you would not have to code for 0 selections. And, you don't really need a macro variable for the OR condition anyway -- if you use the IN operator.
Here's some code (below) to test. My recommendation, at this point, would be to contact Tech Support for help with multiple selections. Multiple selections are hard enough to grasp if you know SAS Macro coding --whether you need SUPERQ, how to use SUPERQ, how to test for NULL values, when values will be NULL in regular code, what other characters need to be handled specially (logical operators, mismatched quotes, parentheses, etc), how to build a string, +more -- and I imagine the code might look like Greek if you're new to SAS programming and concepts AND new to Macro.
I like to think of the SAS Macro facility as an invisible "typewriter" whose only purpose in life is to "auto-type" code for me and send it to the SAS compiler. That is a simplistic explanation, but the whole purpose of the %testcode macro below is to generate these strings:
[pre]
"cat_herder","feather_collector" (for two selections)
"alligator_wader" (for one selction)
"report_writer" (my default if they make NO selections)
[/pre]
If you look at the final WHERE clause and the TITLE statement in the %testdata macro, you will see that I put the rest of my WHERE clause in the "whole" program macro, not in the "code snippet" macro. But, anyway, for the 2 selection situation, I have to generate the "beginning" of the choices:
"cat_herder"
then for the next choice, I have to generate a comma in front of the second, third and ... choices.
,"feather_collector"
when I'm done, with my %do loop, I will have this string in my newly constructed macro variable (let's say that it's called WHERECLS):
"cat_herder","feather_collector"
Then, later in my program, I only use &WHERECLS like this:
where ethnic IN (&wherecls);
This saves me from having to jump through hoops to protect the opening and closing parentheses. The same kind of thing goes on for the 1 selection and the 0 selection situation. Anyway, try this program. If this still doesn't help you, then you really need to get Tech Support to take a look at your real code and help you get it working.
cynthia
(ps I turned on symbolgen, mprint and mlogic, so you could look in the sas log and see how everything was being resolved. But, I recommend that you submit Step 1, look in the log. Then submit step 2, look in the log. compare the code inside the macros to the code that got executed in the log (you can tell the "resolved" macro statements in the log because they will all start with MLOGIC, MPRINT or SYMBOLGEN). SYMBOLGEN shows you the resolution of a single macro var and MPRINT shows you the resolved code and MLOGIC shows you the path through the %IF statements. Then submit step 3, then submit step 4. Review the log at every step.
[pre]
** step 1: create the macro programs and make some data;
data work.sillydata;
length name $8 ethnic $18;
infile datalines;
input name $ ethnic $ joblev ;
return;
datalines;
alma cat_herder 1
bob cat_herder 2
carl alligator_wader 2
dave feather_collector 1
edna report_writer 1
fred alligator_wader 3
george report_writer 2
harry teen_magician 2
ida spell_caster 3
;
run;
%macro testdata;
options mlogic mprint symbolgen;
** new macro to USE where clause with REAL data;
** I modified this from an old jobcode example, so it;
** is just your macro var names on a job code example.;
proc sql;
create table goteth as
select *
from work.sillydata
where ethnic IN (&wherecls);
quit;
proc print data=goteth;
title "Using %superq(wherecls) in SQL";
run;
%mend testdata;
%macro testcode;
%global ethnicity0 wherecls
ethnicity1 ethnicity2 ethnicity;
** the GLOBAL statement ensures that the macro variables are;
** in the GLOBAL symbol table, but will be NULL if no values;
** are sent from the server;
** this is the macro that only builds the WHERE clause;
** I could have put them together but I like to separate;
** out the "whole" macro programs from the ones that just;
** generate code snippets;
options mlogic mprint symbolgen;
** test for 0 selections -- ethnicity macro var would be null;
%if ðnicity = %then %do;
%put --------> DO NOT DO THAT!;
%let ethnicity = report_writer;
%let ethnicity0 = ;
%end;
%if ðnicity0 = %then %do;
** they only made 1 selection which is contained;
** in the ethnicity macro parameter;
%let wherecls = "%superq(ethnicity)";
%put ---> inside first IF;
%put ---> wherecls = &wherecls;
%put (work.ethnic IN (&wherecls));
%end; /* end 1 selection */
%else %do;
** they selected 2 or more;
** so the do loop can be used;
%put =====> inside ELSE;
%do i = 1 %to ðnicity0;
%put &i ** &ðnicity&i;
%if &i = 1 %then %let wherecls = "%superq(ethnicity&i)";
%else %let wherecls = &wherecls,"%superq(ethnicity&i)";
%end; /* end do loop */
** now have the whole string for all their selections;
%put wherecls is &wherecls;
%put what you get when you reference wherecls:;
%put (work.ethnic IN (&wherecls));
%end; /* end else condition */
%mend testcode;
** step 2: run the macro program and simulate that;
** they made 2 choices;
** simulate getting 2 or more parameters;
** if parameter is ethnicity, then for 2 selections;
** macro vars would be: ;
** ethnicity0 would be 2;
** ethnicity1 would be 1st selection;
** ethnicity2 would be 2nd selection;
** ethnicity would be one of the two selections;
%let wherecls = ;
%let ethnicity1 = cat_herder;
%let ethnicity2 = feather_collector;
%let ethnicity0 = 2;
%let ethnicity=feather_collector;
%testcode;
%testdata;
** step 3: Now simulate getting just 1 selection;
** if parameter is ethnicity, then for 1 selection;
** macro vars would be: ;
** ethnicity0 would be null;
** ethnicity1 would not be created;
** ethnicity2 would not be created;
** ethnicity would be THE single selection;
%symdel ethnicity1 ;
%symdel ethnicity2;
%let wherecls = ;
%let ethnicity0 =;
%let ethnicity=alligator_wader;
%testcode;
%testdata;
** step 4: Now simulate getting NO selection;
** if parameter is ethnicity, then for NO selection;
** macro vars would be: ;
** ethnicity would be null;
** ethnicity0 would be null;
** ethnicity1 would not be created;
** ethnicity2 would not be created;
** ethnicity would be THE single selection;
** note that my macro program sets ethnicity to report_writer;
** if there were NO selections;
%symdel ethnicity1 ;
%symdel ethnicity2;
%symdel ethnicity0;
%symdel ethnicity;
%let wherecls = ;
%testcode;
%testdata;
[/pre]