楼主: kimind
22684 9

[原创博文] 怎么计算年龄 [推广有奖]

  • 0关注
  • 0粉丝

小学生

14%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
26 点
帖子
3
精华
0
在线时间
6 小时
注册时间
2010-4-20
最后登录
2016-6-3

楼主
kimind 发表于 2010-7-22 23:03:57 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
各位大虾们,知道每个人的出生年月,怎么计算所有人的年龄?
二维码

扫码加我 拉你入群

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

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

关键词:计算所 所有人

回帖推荐

BraveMadMan 发表于4楼  查看完整内容

有些年龄“四舍五入”了: 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 ...

本帖被以下文库推荐

沙发
BraveMadMan 发表于 2010-7-23 01:18:25
age = floor
((intck('month',birth,somedate)
- (day(somedate) < day(birth))) / 12);
Don't get lost in technical details. What is the big picture?

藤椅
librarynow 发表于 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;

板凳
BraveMadMan 发表于 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
已有 1 人评分热心指数 收起 理由
crackman + 1 热心解答

总评分: 热心指数 + 1   查看全部评分

Don't get lost in technical details. What is the big picture?

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

地板
BraveMadMan 发表于 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
Don't get lost in technical details. What is the big picture?

7
kimind 发表于 2010-7-23 13:38:06
6# BraveMadMan
谢了!

8
librarynow 发表于 2010-7-23 22:44:58
BraveMadMan 发表于 2010-7-23 04:03
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
谢谢 BraveMadMan!学习了!

9
zhentao 发表于 2010-7-24 18:47:41
学习,受教。

10
Rock2000 发表于 2013-3-9 12:40:44
BraveMadMan 发表于 2010-7-23 13:14
为什么不能用yrdif计算年龄?看SAS的官方答案:

“If you use the YRDIF function to calculate a p ...
http://support.sas.com/kb/36/977.html

UPDATE TO THIS NOTE: 15JUL2011 A new option was added to YRDIF in SAS 9.3. This option is called AGE and can be used to calculate a person's age accurately.


好像SAS 9.13 SP4、SAS 9.3版修正这错误了,现在用yrdif可以计算年龄了。


data diff;
     sdate='20Sep1985'd;
     edate='20May2013'd;
     y30260=yrdif(sdate,edate,'30/360');
     yactact=yrdif(sdate,edate,'ACT/ACT');
     yact360=yrdif(sdate,edate,'ACT/360');
     yact365=yrdif(sdate,edate,'ACT/365');
     d30260=datdif(sdate,edate,'30/360');
     dactact=datdif(sdate,edate,'ACT/ACT');
     dact360=datdif(sdate,edate,'ACT/360');
     dact365=datdif(sdate,edate,'ACT/365');
         age=intck('year',sdate,edate);
         days=intck('day',sdate,edate);
     months=intck('month',sdate,edate);
         age1 = floor((intck('month',sdate,edate)- (day(edate) < day(sdate))) / 12);
         format sdate yymmdd10. edate yymmdd10.;
run;

proc print data=diff;
title "YRDIF/DATDIF/INTCK函数比较";
run;

在SAS 9.13 SP4 、 SAS 9.3上结果一致。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 10:43