全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
22602 9
2010-07-22
各位大虾们,知道每个人的出生年月,怎么计算所有人的年龄?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2010-7-23 01:18:25
age = floor
((intck('month',birth,somedate)
- (day(somedate) < day(birth))) / 12);
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-7-23 01:30:10
data aaa;
input birthday mmddyy8.;
bday=put(birthday,mmddyy8.);
today=put(today(),mmddyy8.);
age=intck('year',birthday,today());
cards;
01251956
09021968
02181948
10271999
;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-7-23 04:03:04
librarynow 发表于 2010-7-23 01:30
data aaa;
input birthday mmddyy8.;
bday=put(birthday,mmddyy8.);
today=put(today(),mmddyy8.);
age=intck('year',birthday,today());
cards;
01251956
09021968
02181948
10271999
;
run;
有些年龄“四舍五入”了:

data aaa;
input birthday mmddyy8.;
format birthday mmddyy8.;
bday=put(birthday,mmddyy8.);
today=put(today(),mmddyy8.);
age=intck('year',birthday,today());
age1 = floor
((intck('month',birthday,today())
- (day(today()) < day(birthday))) / 12);
cards;
01251956
09021968
02181948
10271999
;
run;


Obs    birthday      bday       today      age    age1

1     01/25/56    01/25/56    07/22/10     54     54
2     09/02/68    09/02/68    07/22/10    42     41
3     02/18/48    02/18/48    07/22/10     62     62
4     10/27/99    10/27/99    07/22/10     11     10
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-7-23 13:00:09
4# BraveMadMan
你好,谢谢!如果在该数据集用yrdif函数计算年龄,程序是怎么样的?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-7-23 13:14:03
kimind 发表于 2010-7-23 13:00
4# BraveMadMan
你好,谢谢!如果在该数据集用yrdif函数计算年龄,程序是怎么样的?
为什么不能用yrdif计算年龄?看SAS的官方答案:

If you use the YRDIF function to calculate a person's age, you might get incorrect results. This function was designed for the Securities Industry to calculate interest for fixed income securities based on industry rules. Therefore, if you use this function in any other way, your calculation could be incorrect. SAS customers have reported incorrect results when using this function for calculating age. The function apparently does not take into account the extra day in leap years."

出处:http://support.sas.com/kb/36/977.html
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群