Did you have code that worked before you started writing that macro?
If by "database" you mean a SAS Library then this would be my take. The example looks for any data set in the SASHELP library (which you should have) looking for a variable named Sex. Important to note: the case of the variable name in the Name variable can be of variable case. So I use UPCASE for a comparison to 'SEX', an equivalent lower case could be used. SAS will return a numeric 1/0 result for any logical comparison. So this selects the largest of all the comparisons of the names for each Memname. 1 indicates it was found, 0 not.
I strongly recommend using numeric 1 for "Yes" or "True" or "Present" and 0 for "No", "False","Absent" or similar dichotomous values. There things that just plain easier with the numeric values than the character.
proc sql;
create table work.want as
select memname,max(upcase(name)='SEX') as Variable_exists
from dictionary.columns
where LIBNAME='SASHELP'
group by memname
;
quit;
You would have to show an example of how you want your "multiple" , assuming you mean multiple variables, output data set to look.
For example a minor change to my code would give a count of how many variables are in the set:
proc sql;
create table work.want as
select memname,sum(upcase(name)in ('SEX' 'AGE') ) as Variable_exists
from dictionary.columns
where LIBNAME='SASHELP'
group by memname
;
quit;
An example of that "numeric 1/0 is easier to work with" for many things.
... View more