SAS中文论坛

标题: 一个日期函数问题…… [打印本页]

作者: shiyiming    时间: 2008-10-8 11:51
标题: 一个日期函数问题……
求某日期的当前月的最后一天:如日期2008-02-05,用函数求得的结果是2008-02-28
作者: shiyiming    时间: 2008-10-8 16:17
标题: Re: 一个日期函数问题……
so easy
作者: shiyiming    时间: 2008-10-8 16:19
标题: Re: 一个日期函数问题……
[code:m6xh0k0y]data aa;
     input date $10.;
         cards;
2008-01-06
2008-02-01
2008-03-05
2008-04-10
2008-05-12
2008-06-08
2008-07-17
2008-08-02
2008-09-03
2008-10-10
2008-11-21
2008-12-22
;
run;

data temp;
     set aa;
         date1=input(date,yymmdd10.);
         year=year(date1);
         month=month(date1);
         if month in (1,3,5,7,8,10,12) then last=trim(left(year))||"-"||trim(left(put(month,z2.)))||"-31";
         else if month in (4,6,9,11) then last=trim(left(year))||"-"||trim(left(put(month,z2.)))||"-30";
         else if mod(year,4)=0 then do;
            if mod(year,100)=0 and mod(year,400) ne 0 then
                   last=trim(left(year))||"-"||trim(left(put(month,z2.)))||"-28";
            else last=trim(left(year))||"-"||trim(left(put(month,z2.)))||"-29";
         end;
         else last=trim(left(year))||"-"||trim(left(put(month,z2.)))||"-28";
run;[/code:m6xh0k0y]
作者: shiyiming    时间: 2008-10-8 17:55
标题: Re: 一个日期函数问题……
谢谢你,
不过我只是想要一个函数,而不是算法
就像intnx('day','01feb2008',3)一样的函数,
SAS有解决我遇到问题的函数吗
作者: shiyiming    时间: 2008-10-9 09:38
标题: Re: 一个日期函数问题……
你已经知道答案只是你不会用而已,用intnx
作者: shiyiming    时间: 2008-10-9 10:47
标题: Re: 一个日期函数问题……
学习了。
a=intnx('month','06FEB2008'd,0,'E');




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2