在上周日查找并在SAS每周向后四周(Finding last Sunday and going 4 weeks backward every week in SAS)

编程入门 行业动态 更新时间:2024-10-28 11:20:47
在上周日查找并在SAS每周向后四周(Finding last Sunday and going 4 weeks backward every week in SAS)

我每周四都会有一份SAS工作,但有时需要在周三或周二晚上运行。 该工作每隔4周收集一些数据直到最近的星期日。 例如,今天我们有2015年的19月,我需要的数据直到2015年3月15日。

data get_some_data; set all_the_data; where date >= '16Feb2015' and date <= '15Mar2015'; run;

下周我也必须手动更改日期参数

data get_some_data; set all_the_data; where date >= '23Feb2015' and date <= '22Mar2015'; run;

无论如何,我可以自动化呢?

I have a SAS job that runs every Thursday, but sometime it need to run on Wednesday, and maybe Tuesday evening. The job collects some data in 4 week intervals up until the closest Sunday. For example, today we have 19Mar2015, and I need data until 15Mar2015.

data get_some_data; set all_the_data; where date >= '16Feb2015' and date <= '15Mar2015'; run;

Next week I have to manually change the date parameters too

data get_some_data; set all_the_data; where date >= '23Feb2015' and date <= '22Mar2015'; run;

Anyway I can automate this?

最满意答案

我会扩展@ user667489的建议,因为它可能需要一段时间才能解决。 关键是要使用week时间间隔,默认情况下星期天开始(您可以用换档指数改变它,请阅读此处了解更多详情)

所以你的查询只需要是:

where intnx('week',today(),-4)<date<=intnx('week',today(),0);

I'll expand on the suggestion from @user667489 as it could take you a while to work it out. The key is to use the week time interval, which by default starts on a Sunday (you can change this with a shift index, read this for further details)

So your query just needs to be :

where intnx('week',today(),-4)<date<=intnx('week',today(),0);

更多推荐

本文发布于:2023-07-14 13:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1104790.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并在   在上   周日   SAS   week

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!