使用 SAS EG 根据今天的日期选择上一季度的最后一天 [英] Selecting the last day of previous quarter, based on the date of today using SAS EG

查看:67
本文介绍了使用 SAS EG 根据今天的日期选择上一季度的最后一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来根据今天的日期选择上一季度最后一天的日期.我有一个日历维度,如下所示:

I am trying to find a way to select the date of the last day of the previous quarter, based on the date of today. I have a calendar dimension at my dispoasal that looks like the following observations:

维表日历数据示例

已使用以下 SAS 代码来获得上图中的数据:

The following SAS code has been used to have the data like in the previous image:

data test_last_day_qtr;
    set PRDDMT.TD_ENT_CALENDAR;
    TODAY=today();
    QTR_TODAY=qtr(TODAY);
    SAS_DATE_VALUE=datepart(DT_DATE);
    if QTR_TODAY=1;
run;

基于今天是 2016/02/25 的事实,我应该有 31DEC2015:00:00:00 的观察作为输出.

Based on the fact that today is 2016/02/25, I should have to have the obeservation of 31DEC2015:00:00:00 as output.

我的第一个想法是通过执行以下操作仅保留每个季度的最后一次观察:

A first idea that I had was to keep only the last observation of each quarter by doing:

data test_last_day_qtr;
    set PRDDMT.TD_ENT_CALENDAR;
    by ID_YEAR ID_QRT ID_MONTH;
    if Last.ID_MONTH;
run;

但这并没有给我想要的结果:

But this does not give me the result I was hoping for:

每个季度内最后一次观察的子集

即使这确实给了我正确的结果,我也不知道如何取得进展.其他有想法的人吗?

Even if this did gave me the right result, I do not really have an idea on how to progress. Someone else who has an idea?

推荐答案

如果您使用 intnx 函数非常简单,该函数用于将日期向前或向后移动给定的周期数.包括可选的 end 关键字以返回季度的最后一天(默认为开始).

Very simple if you use the intnx function, which is used to move a date forwards or backwards by a given number of periods. Include the optional end keyword to return the last day of the quarter (the default is the beginning).

data _null_;
a = intnx('quarter',today(),-1,'end');
format a date9.;
put a;
run;

这篇关于使用 SAS EG 根据今天的日期选择上一季度的最后一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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