PROC SQL循环:一年中循环了几个月?

问题描述 投票:0回答:1

我无法创建一种有效的方式来使用SAS中的PROC SQL来收集4年(2017年,2018年,2019年,直到2020年现在)的每月数据。

我当前的(缩短的)代码:

PROC SQL;
select 
count(VAL1) as name1, sum(VAL2) as name2
from table  tbl
WHERE tbl.dte  >= '20170101' and tbl.dte < '20170201'
); 

我目前只是一遍又一遍地使用复制和粘贴方法,但是我需要对四张表进行一百次以上的操作(相当于大约500次)。

有没有更有效的方法?

sql loops sas macros proc
1个回答
0
投票

聚合如何?

select year(tbl.dte), month(tbl.dte), count(VAL1) as name1, sum(VAL2) as name2
from table  tbl
where tbl.dte  >= '20170101' and tbl.dte < '20170201'
group by year(tbl.dte), month(tbl.dte)
© www.soinside.com 2019 - 2024. All rights reserved.