-2
%macro chk(lib=,varlist=);
proc sql noprint;
  select distinct catx(".",libname,memname) into : datalist separated by " "
    from dictionary.columns
     where libname = %upcase("&lib") and %upcase(&varlist) = upcase("&varlist");
quit;

data test1;
set &datalist;
run;
proc print data=work.test1;run;
%mend;
%chk(lib=ssp,varlist=name ID height);

my above example searches specific variables in varlist parameter in all DataSets in the specific library grp and appends them. i have 2 DS with all the variables but only the values from the 1 DS is selected & not frm DS 2 & also gives a error. &datalist symbolic reference not found....

Apache11
  • 189
  • 11
  • Your code doesn't do what you state it does, ie append tables or select variables that are equal to 'AGE'. Please take the time to properly formulate your questions. – Reeza Oct 05 '16 at 19:46
  • No it doesn't, if you copy your code into SAS it wouldn't run as is. For starters AGE would need to be in quotation marks. Not sure what's the deal with TEMP. Regardless, I posted an answer in your previous question. – Reeza Oct 06 '16 at 06:30
  • Did you see my comment on your other question? Look at the IN operator http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000780367.htm or use an OR. If a=1 or a=2 ... – Reeza Oct 06 '16 at 17:46

1 Answers1

0

Before you make a macro note what your code should look like without a macro.

In this case it would be

Name in ("Name", "Age", "Sex");

As long as you pass your parameter through with quotes and comma's this would be what you're looking for.

Edit:

%macro chk(lib=,varlist=);
proc sql noprint;
  select distinct catx(".",libname,memname) into : datalist      separated by " "
    from dictionary.columns
     where %upcase(libname) = %upcase("&lib") and %upcase(name) in (&varlist);
quit;

 ***rest of code;
%mend;

You need to pass a valid string to your macro OR process it within the macro first. You haven't specified if you're manually determining the list or pulling it from somewhere. You'll also need to mask the list if you include comma's. Basically, you to find a way to convert the string 'name age sex' into 'NAME', 'AGE', 'SEX' or simply pass it to the macro in that form.

%chk(lib=grp,varlist=%str('NAME', 'AGE', 'SEX'));
Reeza
  • 20,510
  • 4
  • 21
  • 38