I'm using SAS Enterprise Guide. New to writing SAS macro functions. Nested a proc sql inside a macro. I'm trying to first check if a column exists and return the column number and then using the column number, to get the column name so that I can call this macro function in a query builder. However I'm getting ERROR 180-322 under the 'select cats' part of the code. Listed below is the code I have written so far:
%macro varexist(ds,var);
%local rc dsid result dynvar;
%let dsid = %sysfunc(open(&ds));
%let result = %sysfunc(varnum(&dsid,&var));
%let rc =%sysfunc(close(&dsid));
proc sql;
select cats('t1.',name) into :dynvar separated by ', '
from dictionary.columns
where libname = 'WORK' and
memname = 'TRANSPOSE_DATA' and
varnum = "&result";
quit;
&dynvar
%mend varexist;
%put %varexist(WORK.TRANSPOSE_DATA,VAR1);