楼主: lemonxinran
5286 9

请教:sas中有没有程序或函数可以判断某一年是不是闰年 [推广有奖]

  • 0关注
  • 1粉丝

已卖:2份资源

讲师

30%

还不是VIP/贵宾

-

威望
0
论坛币
1155 个
通用积分
6.0000
学术水平
1 点
热心指数
1 点
信用等级
1 点
经验
10334 点
帖子
188
精华
0
在线时间
605 小时
注册时间
2010-10-25
最后登录
2025-4-2

楼主
lemonxinran 发表于 2013-1-15 20:37:13 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
请教:sas中有没有判断某一年是否是闰年的函数或程序。或者能否判断year/4是整数的函数或程序呢?非常感谢解惑!
因为我的数据包括fyear1,endmonth,date。我现在需要取到相对于fyear1结束的那个月(endmonth)的最后一天开始数,往前的366天(对应于date)。
数据举例如下:
fyear1 endmonth  date             roa
2000   05            19980203     0.5
2000   05            19980204     0.6
......
我的想法是把fyear1这一年的endmonth的最后一天day找到,然后用fyear1和endmonth和day拼成字符型数据,再转换为日期时间型和date相减,保留值为0-365的。
由于endmonth中有2月份的数据,因此我需要判断年份是否为闰年,这个应该怎么判断呢?谢谢啦!
二维码

扫码加我 拉你入群

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

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

关键词:有没有 month 字符型数据 mont year 程序

已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Imasasor + 20 + 20 + 1 + 1 + 1 鼓励积极发帖讨论

总评分: 经验 + 20  论坛币 + 20  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

沙发
bbear 发表于 2013-1-15 20:56:58

b=mdy(2,29,1981);
if (b=.) then .... not 闰年

藤椅
tangliang0905 发表于 2013-1-15 22:42:33
if the year is a century year and is NOT divisible by 400 then that century year is NOT A LEAP YEAR.

I find an example online

http://www.sconsig.com/sastips/tip00039.htm         

板凳
goldbaodi 发表于 2013-1-16 11:37:36
Try this Macro.

option Symbolgen Mlogic Mprint;
%macro leapyr (year);
data _null_;
lst_dt="31Dec&year"d;
c=substrn(put(juldate7(lst_dt),7.),5,3);
if c ne "366" then put "&year is NOT Leap year.";
else put "&year is Leap year.";
run;
%mend leapyr;

%leapyr(2000);

---------
Results:
2000 is Leap year.
2001 is NOT Leap year.
2002 is NOT Leap year.
2003 is NOT Leap year.
2004 is Leap year.

报纸
playmore 发表于 2013-1-16 12:42:25
  1. %macro GetIsLeapYearForTable(SourceTable,TargetTable,DateVar,OutputVar);

  2. /* 暂时关闭Log窗口输出 */
  3. proc printto log='recycle bin';
  4. run;

  5. data &TargetTable;
  6.         set &SourceTable;
  7.         &OutputVar.=IFN(INPUT(CATT('29FEB',YEAR(&DateVar)),DATE9.),1,0);
  8. run;

  9. /* 恢复Log窗口输出 */
  10. proc printto log=log;
  11. run;

  12. %exit:
  13. %mend;


  14. %macro Demo();

  15. %let SourceTable=NAVOfFund;
  16. %let TargetTable=TradeDayList;
  17. %let DateVar=End_Date;
  18. %let OutputVar=IsLeapYr;
  19. %GetIsLeapYearForTable(&SourceTable,&TargetTable,&DateVar,&OutputVar);

  20. %mend;
复制代码
playmore邀请您访问ChinaTeX论坛!!!进入ChinaTeX论坛

地板
pobel 在职认证  发表于 2013-1-16 13:04:32
如果楼主是想找到fyear1那一年endmonth对应的月的最后一天,可以用下面的代码:

data test;
  input fyear1 endmonth  date : yymmdd8.        roa;
  format date yymmdd8.;
  cards;
2000   02            19980203     0.5
2000   05            19980204     0.6
2000   07            19980203     0.5
2000   08            19980204     0.6
2000   11            19980203     0.5
2000   12           19980204     0.6
2100   02            19980203     0.5
2008   02            19980204     0.6
2200   02            19980203     0.5
2400   02            19980204     0.6
;

data want;
   set test;
   if endmonth ne 12 then newvar=put(mdy(endmonth+1,1,fyear1)-1,yymmdd10.);
   else newvar=put(mdy(endmonth,31,fyear1),yymmdd10.);

run;
和谐拯救危机

7
lemonxinran 发表于 2013-1-16 14:22:07
tangliang0905 发表于 2013-1-15 22:42
if the year is a century year and is NOT divisible by 400 then that century year is NOT A LEAP YEAR. ...
thanks!

8
lemonxinran 发表于 2013-1-16 14:48:46
goldbaodi 发表于 2013-1-16 11:37
Try this Macro.

option Symbolgen Mlogic Mprint;
非常感谢!

9
lemonxinran 发表于 2013-1-16 14:49:32
playmore 发表于 2013-1-16 12:42
谢谢!

10
lemonxinran 发表于 2013-1-16 14:57:04
pobel 发表于 2013-1-16 13:04
如果楼主是想找到fyear1那一年endmonth对应的月的最后一天,可以用下面的代码:

data test;
嗯,对,我就是想找到endmonth对应的月份最后一天,谢谢啦!

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

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