For those interesed in a solution, as far as I understand all the data steps, the code below seems to do the job. %macro testing(search, searchvalue, where_to_search, result, summary = 0, srchvarlength = $32);
proc sql noprint;
select trim(name) into :names separated by ' ' from &where_to_search.;
/* working value */
select cats(libname,'.', memname,'(keep=', trim(name), ')') into :testsets separated by ' ' from &where_to_search.;
run;
data &result.;
/*
prevent %scan from picking the shortest char-length,
also names per dictonary.columns max length is 32.
*/
length variable $32;
length value &srchvarlength.;
/* set a common length for all variables to be searched */
/* otherwise the hash code might fail */
set &testsets. indsname=dsname ;
if _n_ = 1
then do;
length &searchvalue. &srchvarlength.;
declare hash h (dataset:"&search.");
h.definekey("&searchvalue.");
h.definedone();
call missing(&searchvalue.); /* prevents "uninitialized" message */
end;
%do i = 1 %to %sysfunc(countw(&names.));
if h.check(key:%scan(&names., &i.)) = 0
then do;
dataset = dsname;
variable = "%scan(&names, &i)";
value = %scan(&names., &i.);
output;
end;
%end;
keep dataset variable value;
run;
%mend;
... View more