Using an answer from this thread, I was trying to get to work the following code. I have a list of sql-queries in a table plus an id for each query. Now I'd like to have the results of these queries plus the id as another table.
/* The Macro */
%macro run_query(q,id);
proc sql noprint;
select count into: count
from (&q.) a;
quit;
%mend;
/* Some fake-data */
DATA queries;
INPUT id :$12. query :$3000.;
INFORMAT id $12.;
INFILE DATALINES DSD;
DATALINES;
01,SELECT COUNT(*) AS count FROM sashelp.bweight WHERE Married=1
0101,SELECT COUNT(*) AS count FROM sashelp.bweight WHERE Boy=1
0102,SELECT COUNT(*) AS count FROM sashelp.bweight WHERE Black=1
;
RUN;
/* Make a copy of the dataset */
DATA want;
SET queries;
RUN;
/* Insert the results */
data want;
set queries;
call execute(%nrstr(%run_query('||query||','||id||')));
run;
Can anyone see, what the problem is? The error report looks like this:
execute()
takes string argument. You've provided open code. Could you try actually quoting it with single quotes rather than using%nrstr
. – samkart