SAS 中的日期计算 [英] Date calculations in SAS

查看:122
本文介绍了SAS 中的日期计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为任意 SAS 日期添加 1 天.我有以下有效的代码,但我想知道是否有对这样的日期计算的内置支持:

I want to add 1 day to an arbitrary SAS date. I have the following code that works but I wonder wether there is built-in support for date calculations like this:

proc fcmp outlib=whatever;  
function lastDayInYear(d);  
    if datdif(d,mdy(12,31,year(d)),'ACT/365')=0 then return(1); else return(0);  
endsub;  

function advanceDate(d);
    if d=. then return(.);
    if lastDayInYear(d) then
        return(mdy(1,1,year(d)+1));
    else
        return(datejul(juldate7(d)+1));
endsub;
quit;

推荐答案

Itzy 是对的...只需加 1.如果你想做更高级的日期计算,你可以使用 intnx()intck() 函数.

Itzy is right... just add 1. If you want to do more advanced date calculations you can use the intnx() and intck() functions.

例如

data _null_;
  tomorrow            = date() + 1;
  same_day_next_month = intnx('month',date(),1,'same');
  first_day_next_week = intnx('week' ,date(),1,'beginning');
  last_day_of_year    = intnx('year' ,date(),0,'end');

  put _all_; 
run;

这篇关于SAS 中的日期计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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