SAS:从表中执行 sql 查询字符串? [英] SAS: execute sql query strings out of a table?

查看:27
本文介绍了SAS:从表中执行 sql 查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个包含这样的 sql 查询字符串的表(列 query)

If I have a table containing sql query strings like this (column query)

id  query                                 n
——————————————————————————————-—————————————
1   select count(*) from tab where x=...
2   select count(*) from tab where x=...
... 

在 SAS 中有没有办法将这些查询的结果保存在另一列 n 中?

In SAS is there a way to save the results of these queries in another column n?

推荐答案

只是为了好玩 - 一种只使用 proc sql 的方法:

Just for fun - an approach using only proc sql:

data queries;
input id :8. query :$100.;
infile datalines dsd;
datalines;
1,select count(*) as count from sashelp.class where sex = 'F'
2,select count(*) as count from sashelp.class where sex = 'M'
;
run;

proc sql noprint;
  select catx(' ','select ', id, ' as id,', substr(query, 7)) into :code
    separated by ' union all ' 
    from queries;
  create table want as
    &code;
quit;

只有当所有查询的总长度符合单个宏变量的最大允许长度时,这才有效.如果有疑问,请检查 MVARSIZE 系统选项的值.

This will only work as long as the total combined length of all your queries fits within the maximum allowed length of a single macro variable. If in doubt, check the value of the MVARSIZE system option.

这篇关于SAS:从表中执行 sql 查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆