传递SAS PROC SQL中的表值
我有一个table_a。 的表_a的示例数据
带有名称和日期名称 | 日期 |
---|---|
标记 | 29-apr-22 |
Dave | 05-May-22 |
我想将表_a的名称和日期列传递到以下代码为值。整个代码在SAS中运行。
proc sql;
select table_A.name, table_A.date, count(distinct(table_B.shipments)) as cul_count
from table_B
where table_B.names = table_A.name
and table_B.dates between (table_A.date and date());/*date () is to get today's date*/
quit;
我想传递table_a值。有没有使用连接的方法可以做到这一点?尝试学习动态/参数编码。 无论如何使用加入? 预期输出如下,
名称 | 日期 | CUL_COUNT |
---|---|---|
MARK | 29-APR-22 | 65 |
DAVE | 05-MAY-22 102 | 102 |
I have a table_A. Sample data for table_A with name and dates
name | date |
---|---|
Mark | 29-APR-22 |
Dave | 05-May-22 |
I would like to pass the name and date column of table_A to the following code as values. The whole code is running in SAS.
proc sql;
select table_A.name, table_A.date, count(distinct(table_B.shipments)) as cul_count
from table_B
where table_B.names = table_A.name
and table_B.dates between (table_A.date and date());/*date () is to get today's date*/
quit;
I want to pass table_A values. Is there a way to do this without using joins? Trying to learn dynamic/parametric coding.
And anyway with using joins?
The expected output is as follows
name | date | cul_count |
---|---|---|
Mark | 29-APR-22 | 65 |
Dave | 05-May-22 | 102 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用正确的加入将数据限制在“右”表中,然后加入名称,并指定日期应在(包括)表A。
中的日期之后(包括)
对变量的表引用需要应用于变量而不是函数(即tb。
求和,您想通过通常
包括一个组
编辑来包括一个组:根据您的评论
这是您可以动态构建的查询的手动版本:
这是我最初的尝试。首先,您必须弄清楚如何手动构建上面的零件,然后可以使用Call Execute根据需要构造代码。但是上面的部分是关键。未经测试的括号可能会被关闭,以用于说明目的。
Use a right join to limit the data to the 'right' table and then join on the names and specify that the dates should be after (including) the date in table A.
Alias make it simpler to read the code, ta/tb.
Table references to variables need to apply to the variable not the function (ie tb.shipments not tb.count).
For summations, you want to include a GROUP BY typically
EDIT: based on your comment
This is a manual version of the query you could build dynamically:
Here's my initial attempt at it. First you have to figure out how to manually build the part above, then you can use CALL EXECUTE to construct the code as desired. But the part above is key. Untested, so parentheses may be off, included for illustration purposes.