简体   繁体   English

SAS 从第三个月开始最近三个月的过滤日期

[英]SAS filter date for the last three months from the start of the third month

I would like to filter my dataset to the last three months starting from the first of the month in SAS.我想从 SAS 中的第一个月开始将我的数据集过滤到最后三个月。

I have the following for the yesterday and the last 15 days with macro:昨天和过去 15 天的宏有以下内容:

DATA _NULL_;
    yesterday=put(INTNX('day',&today,-1),DATE11.);
    twoweeksago=put(INTNX('day',&today,-15),DATE11.);
    /*threemonths = put(intnx('month', &today, -3, 'same')*/
    call symput('rpt_dt',yesterday);
    call symput('rpt_dt2',twoweeksago);
    /*call symput('rpt_3',threemonths);*/
RUN;

I tried modifying the yesterday and twoweeks ago lines, as you can see from the commented out lines, but this only works three months from today, which means I am filtering all the way to June 23rd and not the June 1st.我尝试修改昨天和两周前的行,正如您从注释掉的行中看到的那样,但这仅适用于从今天开始的三个月,这意味着我一直过滤到 6 月 23 日而不是 6 月 1 日。

For now the work around is to be explicit about how many days since June 1st, but I am thinking there could be a way to code what I am trying to do.目前的工作是明确说明自 6 月 1 日以来的天数,但我认为可能有一种方法可以对我正在尝试做的事情进行编码。

threemonths = put(intnx('month', &today, -3, 'same')

That's close?那很近? Do you happen to know what the 'same' parameter does.您是否碰巧知道“相同”参数的作用。 It's an alignment specifier.这是一个 alignment 说明符。 See the intnx documentation for the other options - beginning , middle , end (or their initial letter).有关其他选项,请参阅intnx 文档- beginningmiddleend (或它们的首字母)。

threemonths = put(intnx('month', &today, -3, 'B')

That will start on the 1st of the month 3 months ago.这将从 3 个月前的每月 1 日开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM