sas intck函数 月中一日到月底有多少天

From sasCommunity
This article is about the . I believe that the best way to understand how it works is to see some easy examples. Therefore this article contains many of them. Some additional date and time function are also included.
Everyone knows that the INTCK function returns the integer count of the number of interval boundaries between two dates, two times, or two datetime values. (c) SAS Help. In the following Example1 you see how this function works within some basic intervals:
Example1. Date arguments.
years=intck('year','01jan2009'd,'01jan2010'd);
SEMIYEAR=intck('SEMIYEAR','01jan2009'd,'01jan2010'd);
quarters=intck('qtr','01jan2009'd,'01jan2010'd);
months=intck('month','01jan2009'd,'01jan2010'd);
weeks=intck('week','01jan2009'd,'01jan2010'd);
days=intck('day','01jan2009'd,'01jan2010'd);
In the example above we count the difference between two dates: 01-Jan-2009 and 01-Jan-2010 (one year).
The result values will be:
semiyears = 2
quarters= 4
months = 12
weeks = 52
days = 365
Example2. Datetime arguments.
hours=intck('hour','01jan:00'dt,'01jan:00'dt);
minutes=intck('minute','01jan:00'dt,'01jan:00'dt);
seconds=intck('second','01jan:00'dt,'01jan:00'dt);
The result values will be:
hours= 8760
minutes= 525600
Example3. Time arguments.
hours=intck('hour','00:00:00't,'12:00:00't);
minutes=intck('minute','00:00:00't,'12:00:00't);
seconds=intck('second','00:00:00't,'12:00:00't);
In the example3 (above) we count the difference between two time values: 00:00:00 (midnight) and 12:00:00 (midday).
The result values will be:
minutes= 720
seconds= 43200
Important notice! The INTCK functions does not count the number of complete intervals between two values. The example below shows how it calculates the 'YEAR' difference between 31-Dec and 1-Jan:
Example4. Boundaries.
years=intck('year','31dec2009'd,'01jan2010'd);
The result values will be:
Since you know that it is just ONE DAY and it is not a YEAR the results could be mistakenly considered as incorrect. Please be aware that it returns the integer count of the number of interval boundaries between two dates. In the example above the boundary is the value of '01JAN2010'd that is included (just once) into the interval.
My solution is simple. You just have to use 'day365' instead of 'year'. The 'day365' paremeter tells to the INTCK function to multiply day by 365 times. Look at the next example:
Example5. Days multiplied by 365.
days365=intck('day365','31dec2009'd,'01jan2010'd);
The result values will be:
days365 = 0
And that is what we've expected. Actually, you are free to combine it the way you need (e.g. year2 or week4).
Some operations with changing formats are also helpful when you deal with the INTCK function. Please take a look at the next examples. I believe it is quite easy to understand how it works.
Example6. Datepart() Timepart() functions.
format a1 b1 date9.;
a0='01jan:00'
b0='01jan:00'
a1=datepart(a0);
b1=datepart(b0);
days=intck('day',a1,b1);
The result value will be:
days = 365
format a1 b1 date9.;
a0='01jan:00'
b0='01jan:00'
a1=timepart(a0);
b1=timepart(b0);
hour=intck('hour',a1,b1);
The result value will be:
You might find it helpful to use the
along with the INTCK.
Good luck!苹果/安卓/wp
积分 243, 距离下一级还需 17 积分
权限: 自定义头衔
道具: 彩虹炫, 雷达卡, 热点灯, 雷鸣之声, 涂鸦板, 金钱卡, 显身卡, 匿名卡下一级可获得
权限: 签名中使用图片
购买后可立即获得
权限: 隐身
道具: 金钱卡, 雷鸣之声, 彩虹炫, 雷达卡, 涂鸦板, 热点灯
本帖最后由 wanghaidong918 于
03:11 编辑
data _null_;
mob=intck('day365','18dec2009'd,'10oct2010'd);
mob1=intck('day365','19dec2009'd,'10oct2010'd);
mob2=put(intnx('day','10oct2010'd,-365),date9.);
put mob mob1 mob2;
百思不得其解,本来我是想用算类似于注册时长这类的数据,intck(‘year’)算出来,只是将年份与年份相减,不准确,所以用day来算,但是结果是这样
1 0 10OCT2009
不理解啊?明明是365天,它怎么只算了305天呢?求解,谢谢
载入中......
总评分:&学术水平 + 1&
热心指数 + 1&
信用等级 + 1&
For all multiunit intervals except multiweek intervals, the SAS System creates an interval beginning on January 1, 1960, and counts forward from that date to determine where individual intervals begin on the calendar. As a practical matter, when a year can be divided evenly by an interval, think of the intervals as beginning with the current year.
下面的代码可以输出每个 'day365' 区间的第一天。
& &&&from='01jan1960'd;
& &&&format beginner yymmdd10. ;
& &&&do i=0 to 51;
& && && &beginner=intnx('day365',from,i);
& && && &put beginner= ;
part of log:
mob=intck('day365','18dec2009'd,'10oct2010'd);
mob1=intck('day365','19dec2009'd,'10oct2010'd);
'18dec2009'd 和 '10oct2010'd 之间包含了一个beginner &&,所以mob值是1,
'19dec2009'd 和 '10oct2010'd 之间不包含beginner,所以mob1的值是0。
希望对你有点帮助。
总评分:&学术水平 + 1&
热心指数 + 1&
信用等级 + 1&
和谐拯救危机
明白了,谢谢啊,好厉害
最后我这样解决写了
mob=round(('10oct2010'd-datepart(starts))/365);
还有什么其他方法么?或者函数来解决的?
详见帮助,可能会好一点
Let them be hard, but never unjust
初级热心勋章
初级热心勋章
中级热心勋章
中级热心勋章
初级信用勋章
初级信用勋章
初级学术勋章
初级学术勋章
中级信用勋章
中级信用勋章
中级学术勋章
中级学术勋章
高级热心勋章
高级热心勋章
高级学术勋章
高级学术勋章
论坛好贴推荐
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
如有投资本站或合作意向,请联系(010-);
邮箱:service@pinggu.org
投诉或不良信息处理:(010-)
京ICP证090565号
京公网安备号
论坛法律顾问:王进律师苹果/安卓/wp
积分 1398, 距离下一级还需 827 积分
权限: 自定义头衔, 签名中使用图片, 设置帖子权限, 隐身
道具: 彩虹炫, 雷达卡, 热点灯, 雷鸣之声, 涂鸦板, 金钱卡, 显身卡, 匿名卡, 抢沙发, 提升卡下一级可获得
权限: 设置回复可见道具: 沉默卡
购买后可立即获得
权限: 隐身
道具: 金钱卡, 雷鸣之声, 彩虹炫, 雷达卡, 涂鸦板, 热点灯
开心签到天数: 154 天连续签到: 1 天[LV.7]常住居民III
本帖最后由 wanghaidong918 于
20:58 编辑
有没有一个函数可以计算出两个日期之间的月数啊?比如和之间的月份数要怎么用sas程序计算呢?就我目前的资料,还不知道怎么计算月数的,所以请高人指点哈,谢谢谢谢!!!
载入中......
intck function
非常感谢!!!
总评分:&学术水平 + 1&
热心指数 + 1&
信用等级 + 1&
好的,谢谢版主哈!O(∩_∩)O哈哈~
好诗,吟的好诗。
Lz可以搜索一下我之前发的一个帖子,讲了intck这个函数的使用方法~~~
初级热心勋章
初级热心勋章
中级热心勋章
中级热心勋章
初级学术勋章
初级学术勋章
初级信用勋章
初级信用勋章
论坛好贴推荐
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
如有投资本站或合作意向,请联系(010-);
邮箱:service@pinggu.org
投诉或不良信息处理:(010-)
京ICP证090565号
京公网安备号
论坛法律顾问:王进律师苹果/安卓/wp
积分 172, 距离下一级还需 88 积分
权限: 自定义头衔
道具: 彩虹炫, 雷达卡, 热点灯, 雷鸣之声, 涂鸦板, 金钱卡, 显身卡, 匿名卡下一级可获得
权限: 签名中使用图片
购买后可立即获得
权限: 隐身
道具: 金钱卡, 雷鸣之声, 彩虹炫, 雷达卡, 涂鸦板, 热点灯
开心签到天数: 4 天连续签到: 1 天[LV.2]偶尔看看I
大家肯定知道自己几岁,度过了多少个季节。那多少人知道自己从出生到现在有多少个月,多少个周、多少天吗?SAS可以帮你解决,用intck函数,将你的出生日期和今天的日期放在下列函数就OK!试一试吧!可以应用到客户的入网时长等计算中。Format x date9. Y date9.;X='14feb1991'd;Y='21jan2013'd;year=Intck('year',x,y);qtr=Intck('qtr',x,y);month=Intck('month',x,y);week=Intck('week',x,y);day=Intck('day',x,y);put year= qtr= month= week= day=;
载入中......
鼓励积极发帖讨论
总评分:&热心指数 + 5&
%macro yourdays(birthday=);
data _null_;
y=today();
year=Intck('year',x,y);
qtr=Intck('qtr',x,y);
month=Intck('month',x,y);
week=Intck('week',x,y);
day=Intck('day',x,y);
put &你在这个世界上活了&year&年,&
& & month&月,& week&星期,& day&天。&;
%yourdays(birthday='08jun1988'd);
做得好一点,要用宏程序嘛,设置成今天就行了
总评分:&学术水平 + 1&
热心指数 + 1&
信用等级 + 1&
技术改变世界
你真厉害,本来想用宏的,但给我弄错了。有空多多指教啊!
SAS 英雄会的新生Lybin,是不是有特别福利呢?
给你发点福利
总评分:&经验 + 60&
论坛币 + 100&
学术水平 + 2&
热心指数 + 2&
信用等级 + 2&
不错,蛮有意思的
理论和实用结合
又改了一下
优化了一下内容%macro yourdays(birthday=);
data _null_;
time=time();
y=today();
x=&
year=Intck('year',x,y);
qtr=Intck('qtr',x,y);
month=Intck('month',x,y);
week=Intck('week',x,y);
day=Intck('day',x,y);
put 100*'*';
put &现在是&y:yymmdd10.&号& time:time5.&分。&;
put &截止到目前,你在这个世界上活了&year&年,&
& & month&个月,& week&个星期,& day&天。&;
put &请珍惜你生命中的每一天!&;
put 100*'*';
/*将以下日期改为你的生日,直接运行全部程序*/
%yourdays(birthday='08jun1988'd);复制代码
热心帮助其他会员
总评分:&学术水平 + 1&
热心指数 + 1&
信用等级 + 1&
技术改变世界
luckychll 发表于
你真厉害,本来想用宏的,但给我弄错了。有空多多指教啊!
SAS 英雄会的新生Ly ...太好了,福利真多,真开心!……
Imasasor 发表于
又改了一下
优化了一下内容出来结果了,漂亮!
(30.53 KB)
17:23:22 上传
Imasasor 发表于
又改了一下
优化了一下内容你好!冒昧打扰,不好意思!~
我是SAS初学者,小草一枚~~看到你编的这个程序觉得很有意思,可是不知道为什么,我电脑上运行时候,显示的是:“现在是 号16:57 分。”。。。其实现在的时间应该是2014年。不知道问题出在哪里。请指教!谢谢!
munin 发表于
你好!冒昧打扰,不好意思!~
我是SAS初学者,小草一枚~~看到你编的这个程序觉得很有意思,可是不知道为 ...你在破解SAS过程中用的破解方法修改了SAS获取的系统时间
简单来说你的SAS获得的系统时间不是你电脑的系统时间
所以不要管了
技术改变世界
Imasasor 发表于
你在破解SAS过程中用的破解方法修改了SAS获取的系统时间
简单来说你的SAS获得的系统时间不是你电脑的系 ...懂了!谢谢!
初级学术勋章
初级学术勋章
初级热心勋章
初级热心勋章
初级信用勋章
初级信用勋章
中级热心勋章
中级热心勋章
中级学术勋章
中级学术勋章
论坛好贴推荐
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
如有投资本站或合作意向,请联系(010-);
邮箱:service@pinggu.org
投诉或不良信息处理:(010-)
京ICP证090565号
京公网安备号
论坛法律顾问:王进律师}

我要回帖

更多关于 sas intck 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信