【问题标题】:How do defining the first and last day of the month如何定义每月的第一天和最后一天
【发布时间】:2021-12-11 13:49:13
【问题描述】:

我有一个问题要问你。是否有机会创建一个类似于此的宏,但在 quera 的 prco sql 中,它总是选择每月的第一天和最后一天。

%let thismonth=%sysfunc(putn(%sysfunc(today()),yymmn6.));

    where t1.DATE = &thismonth
        and _dly.  between t2.data_from and t2.data_to 
        and &gv_date_dly.  between t3.data_from and t3.data_to 
        and t3.obj_code not in ('G07','N06','N07') 

当函数 & thismonth 被调用时,我们将日期从当月的第一天和 date_to 召回到该月的最后一天

【问题讨论】:

  • 这里不清楚你想要什么。您想要当前月份(由 TODAY() 函数生成的日期的月份)吗?还是其他月份?如果其他月份,来源是什么?宏变量?正在查询的数据中的一些变量?您是否试图找到特定变量恰好是这两天(每月第一天或最后一个月)的观察结果?或者日期在某个时间间隔内的值?或者数据中两个日期指示的某个间隔包含日期的值?或与本月的任何部分重叠?
  • 显示一些输入数据和所需的结果输出。包括选择的日期和未选择的数据的示例。

标签: sql sas


【解决方案1】:

定义当月的第一天/最后一天:

%let first = %sysfunc(intnx(month,%sysfunc(today()),0,b));
%let last  = %sysfunc(intnx(month,%sysfunc(today()),0,e));

【讨论】:

  • 谢谢!我应该为此转换我的代码:` t1.Date between &first_day and &last_day and t2.data_from = &first and t2.data_to = &last and t3.data_from = &first and t3.data_to = &last` ?
猜你喜欢
  • 1970-01-01
  • 2019-03-04
  • 1970-01-01
  • 2011-11-24
  • 2015-02-06
  • 2016-02-09
  • 2014-03-22
  • 1970-01-01
  • 2012-04-14
相关资源
最近更新 更多