【问题标题】:Selecting first of month sas dates选择月初 sas 日期
【发布时间】:2013-07-24 09:48:06
【问题描述】:

我有一个包含多个观察值的 sasdataset,其中一个变量称为 DATO。

此变量包含将观察添加到数据集的日期。

以前我用过以下:

WHERE (DATE() - DATO) < 250;    

选择要打印的观察,但这会带来问题。以前我每月添加观察,但现在我每天都这样做。

我需要找到一种方法来仅打印过去 8 个月第一天的观察结果。

我可能可以找出 8 个月的问题,但不知道如何仅选择该月的第一天。任何帮助将不胜感激。

【问题讨论】:

    标签: date sas


    【解决方案1】:
    data _null_;
    infile cards;
    input DATO:date9.;
    if day(DATO)=1 /* first of the month */
        and DATO>intnx('MONTH',date(),-8) /* returns date shifted back 8 months */
        then put DATO= date9.;
    cards;
    01JAN2013
    02JAN2013
    01FEB2013
    01MAR2013
    03MAR2013
    ;run;
    

    结果:

    DATO=01JAN2013
    DATO=01FEB2013
    DATO=01MAR2013
    

    【讨论】:

    • 你的函数应该是 INTNX,而不是 INTCK!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-30
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 2016-08-24
    • 1970-01-01
    相关资源
    最近更新 更多