楼主: shj981222
18308 18

【请教】如何用weekday函数求星期几、为什么我的错了 [推广有奖]

11
wolfcrying 发表于 2008-3-25 11:44:00

真是晕,SAS是美国人开发的 ,美国人认为(Tuesday)是一个星期的第5天,(Sunday)是每个星期的第1天, 明白了吧

12
shj981222 发表于 2008-3-25 12:11:00
恩,是够晕的,谢谢
To be rong is fine, but to stay rong is unforgivable.

13
wxq1638 发表于 2008-3-25 12:22:00
其实不如自己编写一家伙山,比如以2000年1月1日0点为基点求星期、季度等情况多实用。

14
wxq1638 发表于 2008-3-30 21:38:00

兄弟,我很抱歉!那天回信后便不能再跟贴或发帖子了,除了在cos name论坛还能发帖子外,邮件也不能回了。

搞了两天,系统重装,目前终于恢复正常。

虽然你已经解决的差不多 现仍然根据回忆将此原定跟贴发出:

首先将本程序存入永久数据库

data a;

input m d;

sumd+d;

cards;

 1 31

 2 28

 3 31

 4 30

 5 31

 6 30

 7 31

 8 31

 9 30

10 31

11 30

12 31

;

data sasuser.wxq168;

set a;run;

调用编程

proc data=sasuser.wxq168;

data a;set sasuser.wxq168;if m^=3 then delete;/*当前月份*/

x=mod(sum((2008-y0)*t,sumd-(d-28+1),6+(2008-y0)/4+1),i);/*2008当前年,28当前日,6表示基年11日是星期6,

(2008-y0)/4+1)2000年每4年在2月润1*/

proc print;run;

结果     02年3月28

proc data=sasuser.wxq168;

data a;set sasuser.wxq168;if m^=3 then delete;/*当前月份*/

x=floor(mod(sum((2002-y0)*t,sumd-(d-28+1),6+(2002-y0)/4+1),i));

 

                                                             SAS 系统                   2008年03月28 星期五 下午085057  29

 

                                         Obs     y0      t     i    m     d    sumd    x

 

                                          1     2000    365    7    3    31     90     4

0365

proc data=sasuser.wxq168;

data a;set sasuser.wxq168;if m^=6 then delete;/*当前月份*/

x=floor(mod(sum((2003-y0)*t,sumd-(d-5+1),6+(2003-y0)/4+1),i));

 

                                                             SAS 系统                   2008年03月28 星期五 下午085057  30

                                         Obs     y0      t     i    m     d    sumd    x

 

                                          1     2000    365    7    6    30     181    4

 

08328

proc data=sasuser.wxq168;

data a;set sasuser.wxq168;if m^=3 then delete;/*当前月份*/

x=floor(mod(sum((2008-y0)*t,sumd-(d-28+1),6+(2008-y0)/4+1),i));/*2008当前年,sumd该年到该日累计天数,

d当月最大天数,28当前日,1基年1号,6表示基年11日是星期6,

(2008-y0)/4+1)2000年每4年在2月润1*/

proc print;run;

                                                             SAS 系统                   2008年03月28 星期五 下午085057  31

 

                                         Obs     y0      t     i    m     d    sumd    x

 

                                          1     2000    365    7    3    31   

 

 

15
milagro624 发表于 2008-3-31 12:33:00
程序跑出来的5是指星期四,参见帮助文档:

WEEKDAY Function



Returns the day of the week from a SAS date value
Category: Date and Time

Syntax
Arguments
Details
Examples

Syntax

WEEKDAY(date)

Arguments

date

specifies a SAS expression that represents a SAS date value.


Details

The WEEKDAY function produces an integer that represents the day of the week, where 1=Sunday, 2=Monday, ..., 7=Saturday.


Examples

16
shj981222 发表于 2008-3-31 12:42:00

谢谢

To be rong is fine, but to stay rong is unforgivable.

17
wxq1638 发表于 2008-3-31 18:55:00
已阅

18
wlnk 发表于 2011-1-4 09:19:05
11# wolfcrying

大赞,我也晕了,搞了老半天。。。
你若不想做,会找到一个借口;你若想做,会找到一个方法。

19
wty817 发表于 2014-11-7 10:34:25
shj981222 发表于 2008-3-25 10:39
谢谢指点,感觉理解了上面你们给的解答,可为什么用上面wolfcrying和olover的程序得出来的是星期五,而事实 ...
因为,sas遵循的是国外对星期几的理解。国外认为一个星期的第一天是星期日。所以weekday求出来的,1代表星期日,2代表星期一,以次类推5代表星期四。

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

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