SAS:使用宏运行 SQL 查询 [英] SAS: Run SQL-query using a macro
本文介绍了SAS:使用宏运行 SQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用来自
解决方案
In part/* Insert the results */你基本上将所有的值/结果发送到 dev null 和 data 步骤:
data _null_;
改为尝试:
需要的数据;
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:
解决方案
In part /* Insert the results */ you're basically sending all your values/results into dev null with the data step:
data _null_;
Instead try:
data want;
这篇关于SAS:使用宏运行 SQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文